<!--
copcall = !1;
callme = !1;
callback = !1;
var blinkerT = [];
typerT = setTimeout(function () {}, 10000);
msound = new Audio;
mwalk = new Audio;
mloop = [];
music = !1;
mloops = ['mloop1', 'mloop2', 'mloop3', 'mloop4'];
mwalks = ['walking1', 'walking2', 'walking3', 'walking4'];
loopfile = [];
looptimer = [];
fadetimer = [];
nomove = !1;

function randomloop(loopinput, slot) {
    if (!music) {
        loopfile[slot] = loopinput
    } else if (mloop[slot] && mloop[slot].paused == !1 && loopinput == loopfile[slot]) {} else {
        loopfile[slot] = loopinput;
        clearTimeout(fadetimer[slot]);
        clearTimeout(looptimer[slot]);
        if (mloop[slot]) {
            mloop[slot].pause();
            mloop[slot].currentTime = 0
        }
        mloop[slot] = new Audio('sound/' + Pick(loopinput) + '.ogg');
        mloop[slot].play();
        if (slot == 0) mloop[0].volume = 0.6;
        if (slot == 1) mloop[1].volume = 0.7;
        mloop[slot].addEventListener('playing', function pl(e) {
            nextloop = (this.duration - .05) * 1000;
            looptimer[slot] = setTimeout(function () {
                if (mloop[slot]) {
                    mloop[slot].pause();
                    mloop[slot].currentTime = 0
                }
                randomloop(loopinput, slot)
            }, nextloop);
            e.currentTarget.removeEventListener(e.type, pl)
        }, {
            once: !0
        })
    }
}

function fadeloop(n, mute) {
    if (!mloop[n]) {
        if (!mute) loopfile[n] = '';
        return
    }
    if (mloop[n].volume > 0.01) {
        mloop[n].volume -= 0.006;
        if (mute) speed = 5;
        else speed = 20;
        fadetimer[n] = setTimeout(function () {
            fadeloop(n, mute)
        }, speed)
    } else {
        mloop[n].pause();
        if (!mute) loopfile[n] = '';
        clearTimeout(looptimer[n])
    }
}

function Act(command) {
    window.scrollTo(0, 0)
    newmenu = !0;
    talking = !1;
    killTimeouts();
    randomloop(mloops, 0);
    ToggleStats(0);
    if (command == "UsePhero") {
        Add("You use the monster pheromones. They should last as long as you're here.");
        newmenu = !1;
        Gear.splice(Gear.indexOf("ph"), 1);
        Phero = !0;
        Pheromap = Previous;
        document.getElementById("Use pheromones").remove()
    }
    if (Phero && command != Pheromap && ((command.indexOf("Ex") != -1) || (command.indexOf("Capture") == -1 && command.indexOf("PutInTruck") == -1 && command != "UsePhero"))) {
        Phero = !1
    }
    if (command == "List Monsters") {
        Option();
        Main.innerHTML = '';
        if (Previous == 'Ranch') sound('ranch2');
        if (YourMonsters[0] == '0') {
            Add("Sadly, a recent breakout of monster flu totally wiped out your stock of monsters. These things happen–it's just part of the trade.")
            Add("Better get out there and find some new monsters!")
        } else if (YourMonsters.length == 0) Add("You have no monsters!");
        else {
            if (YourMonsters.length >= (StableCap * .9) && Chance(.08)) {
                lostmon = Math.floor(Math.random() * YourMonsters.length);
                Add("Oh no! " + Article(YourMonsters[lostmon], !0, "Your") + " has run away.");
                if (YourMonsters[lostmon] == 'Invisible Man') Add("(You think.)");
                LogLine("Lost " + Article(YourMonsters[lostmon], !1) + ".");
                LoseMonster(lostmon);
                SaveGame()
            }
            if (YourMonsters.length > (StableCap + 10)) Add("Your stables are very overcrowded! Your monsters are suffering under these conditions.<br>Neighbors are likely to report you.");
            else if (YourMonsters.length > StableCap) Add("Your stables are over safe capacity!<br>Be careful, or the neighbors might report you.");
            else if (YourMonsters.length > (StableCap * .9)) Add("Your stables are nearing safe capacity.");
            if (YourMonsters.includes('Gremlin') && Chance(.06)) {
                YourMonsters.push('Gremlin')
            }
            if (YourMonsters.length == 1) Add("You have one monster:");
            else Add("You have " + YourMonsters.length + " monsters:");
            MonsterList('SelectMonster_');
            if (YourMonsters.length > 1) {
                Main.innerHTML += "<p align='right'><small><small><a href='#' onclick='sortmonsters(); return false;'>sort</a></small></small></p>"
            }
        }
        Option("<Back", "Ranch")
    }
    if (command == "Intro") {
        Say("You are a monster breeder.");
        Add("People have grown tired of the same old scares. The real money is in <i>designer monsters</i>.");
        Add("By crossbreeding traditional monsters, you can discover exciting NEW creeps and fiends, never before imagined.");
        Add("So let's go breed some monsters!");
        sendEvent('Start', 'monsters', YourMonsters.length);
        sendEvent('Start', 'hybrids', HybridsBred());
        Option();
        Option("Music", "RanchMusic");
        Option("No Music", "Ranch")
    }
    if (command == "RanchMusic") {
        if (!music) ToggleMusic();
        command = "Ranch"
    }
    if (command == "Ranch") {
        Option();
        fadeloop(1);
        if (TruckMonsters.length == 0 && ((YourMonsters.length > (StableCap + 10) && Chance(.20)) || (YourMonsters.length > StableCap && Chance(.08)))) {
            Main.innerHTML = '';
            Option();
            sound('bad');
            Add("<span id='uhoh'>Uh oh!</span>");
            Blink('uhoh', 3);
            Add("The local authorities have raided your ranch following reports of inhumane conditions.");
            oc = Cash;
            om = YourMonsters.length;
            Cash = 0;
            YourMonsters = [];
            TruckMonsters = [];
            Parents = [];
            Flags = [];
            LogLine("Lost all monsters in a raid.");
            sendEvent('Raid', 'Stablecap', StableCap);
            SaveGame();
            setTimeout(function () {
                Add("Your " + om + " monsters have been set free and you've been fined $" + oc + ".")
            }, 3000);
            setTimeout(function () {
                Add("<br><span id='speech'>OFFICER KYLE: <span id='spoken'></span><span id='tospeak'></span></span>");
                Typewrite(-1, "My god... Who's the real monster here?");
                Option("Okay", "Ranch")
            }, 5000)
        } else {
            if (TruckMonsters.length > 0) {
                capturelist = Article(Monsters[TruckMonsters[0]], !0, 'your new');
                for (i = 1; i < TruckMonsters.length; i++) {
                    if (TruckMonsters[i]) {
                        if (TruckMonsters[i + 1]) capturelist += ", " + Monsters[TruckMonsters[i]].toUpperCase();
                        else capturelist += " and " + Monsters[TruckMonsters[i]].toUpperCase()
                    }
                }
                Say("You unload your truck and place " + capturelist + " in the stables.");
                if (YourMonsters[0] == '0') YourMonsters = [];
                for (i = 0; i < TruckMonsters.length; i++) {
                    YourMonsters.push(Monsters[TruckMonsters[i]])
                }
                TruckMonsters = [];
                if (YourMonsters.length > StableCap) Add("<br>Your stables are over safe capacity!<br>Be careful, or the neighbors might report you.")
            } else if (['Intro', 'List Monsters', 'Catalog', 'Ranch', 'Phone', 'Phone2', 'Phone3', 'Sell'].includes(Previous)) {
                Say("You are at your ranch.");
                Add("From here you can visit your monsters in the stables, browse the breeder catalog, or get in your truck and go exploring.")
            } else if (Previous.includes('EnterB') || Previous.includes('Dispute')) {
                Say("You return to your ranch and return your monster to the stables.")
            } else Say("You return to your ranch and unload the gear from your truck.");
            if (HybridsInStable(!0) > 0 && (Chance(Math.min(.1 + (HybridsBred() * .02), .90)) || callme) && !callback) {
                Add("<br><span id='phone'>Your telephone is ringing!</span>");
                Blink('phone', 3);
                Option("~Answer the phone", "Phone");
                callme = !1;
                sound('phone')
            } else sound('ranch1');
            SaveGame();
            Main.innerHTML += "<p id='savetext'>Game Saved. <a href='#' onclick='importexport(); return false;'>exp./imp.</a></p>";
            Main.innerHTML += "<div style='clear:both;'></div>";
            Option("Visit the monster stables", "List Monsters");
            if (callback) {
                Option("~Call " + CallerName + " back", "Phone2")
            }
            Option("Browse the catalog", "Catalog");
            Option("Go Exploring", "Travel")
        }
    }
    if (command == "Catalog") {
        Option();
        if (Previous == 'Ranch') sound('ranch3');
        Say("A few items catch your eye in Monster Breeder Direct:");
        Option("Aquatic Monster Specialty Gear", "Cat_AqGear");
        Option("Aerial Monster Specialty Gear", "Cat_AeGear");
        Option("Monster Pheromones", "Cat_Phero");
        Option("Creature Rover XL", "Cat_Truck2");
        Option("Shriek Shuttle XXL", "Cat_Truck3");
        Option("Doomsday Monster Rig XXXXL", "Cat_Truck4");
        Option("Stables Addition", "Cat_Addition");
        Option("Monster Breeding License", "Cat_License");
        Option("Monster Beauty Pageant Flyer", "PageantFlyer");
        Option("<Back", "Ranch")
    }
    if (command.split("_")[0] == "Cat") {
        item = command.split("_")[1];
        Option();
        if (TruckCap < 18) tradein = 750;
        else if (TruckCap < 27) tradein = 1500;
        else if (TruckCap < 45) tradein = 3750;
        else if (TruckCap >= 45) tradein = 7500;
        if (item == "Truck2") {
            price = 2000;
            if (price - tradein < 0) tradeinprice = "-$" + (0 - (price - tradein)).toLocaleString();
            else tradeinprice = "$" + (price - tradein).toLocaleString();
            Say("<center>The Creature Rover XL</center><br>");
            Add("Holds up to six average size monsters with ease. Can also fit one large monster.");
            if (TruckCap == 18) Add("<br>You already own this truck!");
            else {
                Add("<br>List price: $" + price.toLocaleString());
                Add("With trade-in: " + tradeinprice);
                Add("You have: $" + Cash.toLocaleString());
                if (Cash >= price - tradein) Option("Purchase for " + tradeinprice, "Buy_Truck2")
            }
        }
        if (item == "Truck3") {
            price = 5000;
            if (price - tradein < 0) tradeinprice = "-$" + (0 - (price - tradein)).toLocaleString();
            else tradeinprice = "$" + (price - tradein).toLocaleString();
            Say("<center>Shriek Shuttle XXL</center><br>");
            Add("Comfortably seats up to nine average size monsters or two large monsters. Can also fit one colossal monster.");
            if (TruckCap == 27) Add("<br>You already own this truck!");
            else {
                Add("<br>List price: $" + price.toLocaleString());
                Add("With trade-in: " + tradeinprice);
                Add("You have: $" + Cash.toLocaleString());
                if (Cash >= price - tradein) Option("Purchase for " + tradeinprice, "Buy_Truck3")
            }
        }
        if (item == "Truck4") {
            price = 8000;
            if (price - tradein < 0) tradeinprice = "-$" + (0 - (price - tradein));
            else tradeinprice = "$" + (price - tradein);
            Say("<center>The Doomsday Monster Rig XXXXL</center><br>");
            Add("The biggest monster transport on the market! Can easily fit two gigantic monsters, four large monsters, or fifteen average size monsters.");
            if (TruckCap == 45) Add("<br>You already own this truck!");
            else {
                Add("<br>List price: " + price.toLocaleString());
                Add("With trade-in: " + tradeinprice);
                Add("You have: $" + Cash.toLocaleString());
                if (Cash >= price - tradein) Option("Purchase for " + tradeinprice, "Buy_Truck4")
            }
        }
        if (item == "AqGear") {
            Say("<center>Aquatic Monster Specialty Gear</center><br>");
            Add("Water-dwelling monsters are no match for this high-grade specially-designed monster-catching gear.");
            if (Gear.includes('aq')) Add("<br>You already own this equipment!");
            else {
                Add("<br>List price: $500");
                Add("You have: $" + Cash.toLocaleString());
                if (Cash >= 500) Option("Purchase for $500", "Buy_AqGear")
            }
        }
        if (item == "AeGear") {
            Say("<center>Aerial Monster Specialty Gear</center><br>");
            Add("Monsters gifted with flight won't evade this high-grade specially-designed monster-catching gear.");
            if (Gear.includes('fl')) Add("<br>You already own this equipment!");
            else {
                Add("<br>List price: $500");
                Add("You have: $" + Cash.toLocaleString());
                if (Cash >= 500) Option("Purchase for $500", "Buy_AeGear")
            }
        }
        if (item == "Phero") {
            Say("<center>Mosier's Monster Phero-\"Moans\"™</center><br>");
            Add("Mosier's humanely extracted monster pheromones are guaranteed to increase your monster encounters. Simply slather your clothes and hair with this patented mix of monster secretions and you'll be spooked from all directions. That's Mosier's guarantee!");
            Add("<br>List price: $100");
            Add("You have: $" + Cash.toLocaleString());
            if (Cash >= 100) Option("Purchase for $100", "Buy_Phero")
        }
        if (item == "Addition") {
            Say("<center>Build An Addition To Your Stables</center><br>");
            Add("Your current stables comfortably houses " + StableCap + " monsters. Building an addition would increase your safe capacity to " + (StableCap + 15) + ".");
            Add("<br>Project cost: $6,000");
            Add("You have: $" + Cash.toLocaleString());
            if (Cash >= 6000) Option("Add on for $6,000", "Buy_Addition")
        }
        if (item == "License") {
            Say("<center>Monster Breeding License</center><br>");
            Add("Breeding monsters without official certification by the National Board of Monster Breeders can result in fines of up to $50,000.");
            if (Gear.includes('lc')) Add("<br>You are already licensed!");
            else {
                Add("<br>(Meh, who needs a license? What a bunch of bureaucratic nonsense.)");
                Add("<br>List price: $15,000");
                Add("You have: $" + Cash.toLocaleString());
                if (Cash >= 15000) Option("Purchase for $15,000", "Buy_License")
            }
        }
        Option("<Back", "Catalog")
    }
    if (command.split("_")[0] == "Buy") {
        item = command.split("_")[1];
        Option();
        sound('m6');
        if (TruckCap < 18) tradein = 750;
        else if (TruckCap < 27) tradein = 1500;
        else if (TruckCap < 45) tradein = 3750;
        else if (TruckCap >= 45) tradein = 7500;
        if (item == "Truck2") {
            Say("You sell your current truck for $" + tradein.toLocaleString() + " and purchase the Creature Rover XL for $2,000.");
            Cash += tradein - 2000;
            TruckCap = 18;
            sendEvent('Buy', 'Creature Rover XL')
        }
        if (item == "Truck3") {
            Say("You sell your current truck for $" + tradein.toLocaleString() + " and purchase the Shriek Shuttle XXL for $4,000.");
            Cash += tradein - 4000;
            TruckCap = 27;
            sendEvent('Buy', 'Shriek Shuttle XXL')
        }
        if (item == "Truck4") {
            Say("You sell your current truck for $" + tradein.toLocaleString() + " and purchase the Doomsday Monster Rig XXXXL for $8,000.");
            Cash += tradein - 8000;
            TruckCap = 45;
            sendEvent('Buy', 'Doomsday Monster Rig XXXXL')
        }
        if (item == "AqGear") {
            Say("You buy the aquatic gear for $500. Should come in handy for capturing those moist monsters!");
            Cash -= 500;
            Gear.push('aq');
            sendEvent('Buy', 'Aquatic Gear')
        }
        if (item == "AeGear") {
            Say("You buy the aerial gear for $500. Should be useful when flying monsters come to roost!");
            Cash -= 500;
            Gear.push('fl');
            sendEvent('Buy', 'Aerial Gear')
        }
        if (item == "Phero") {
            Say("You buy a bottle of monster pheromones for $100. You'll be irresistible with this!");
            Cash -= 100;
            Gear.push('ph');
            Gear.push('ph');
            Gear.push('ph');
            sendEvent('Buy', 'Pheromones')
        }
        if (item == "Addition") {
            Say("You contract an addition to your stables for $6,000. Ample room for more monsters!");
            Cash -= 6000;
            StableCap += 15;
            sendEvent('Buy', 'Stable Addition')
        }
        if (item == "License") {
            Say("You buy the Monster Breeding License for $15,000. Now you can sleep at night!");
            Cash -= 15000;
            Gear.push('lc');
            sendEvent('Buy', 'Breeding License')
        }
        Option("<Back", "Catalog")
    }
    if (command.split("_")[0] == "PageantFlyer") {
        Option();
        Pageant()
    }
    if (command.split("_")[0] == "SubmitPageant") {
        Say('Which of your fine monsters would you like to enter into the contest?')
        Option();
        for (var i = 0; i < YourMonsters.length; i++) {
            if (Parents[i]) Option("~• " + YourMonsters[i], 'EnterA_' + i)
        }
        for (var i = 0; i < YourMonsters.length; i++) {
            if (!Parents[i]) Option("• " + YourMonsters[i], 'EnterA_' + i)
        }
        Option("<Back", "Catalog")
    }
    if (command.split("_")[0] == "EnterA") {
        mon = command.split("_")[1];
        Option();
        Cash -= 1000;
        LogLine("Spent $1000 entering " + Article(YourMonsters[mon], !1, "your") + " into a pageant.");
        Say("You pack " + Article(YourMonsters[mon], !1, "your") + " into your truck and drive to the Monster Convention Center, where the Monster Beauty Pageant is being held.");
        Add("After paying the $1,000 entry fee, you and your monster step into the show ring.");
        setTimeout(function () {
            Add("<span id='speech'>JUDGE: <span id='spoken'></span><span id='tospeak'></span></span>");
            Typewrite(-1, 'Please walk your monster towards the center of the ring.');
            Option("Walk " + Article(YourMonsters[mon], !0, "your"), 'EnterB_' + mon)
        }, 2000)
    }
    if (command.split("_")[0] == "EnterB") {
        mon = command.split("_")[1];
        Option();
        if (Parents[mon]) {
            par1traits = Monsters[Parents[mon].split(',')[0]];
            par2traits = Monsters[Parents[mon].split(',')[1]];
            hybridtraits = HybridizeTraits(par1traits, par2traits);
            subtr = HybridizeTraits(par1traits, par2traits)
        } else {
            subtr = GetTraits(YourMonsters[mon])
        }
        pagtrx = Pag.slice();
        tc = 0;
        for (x in Pag) {
            if (subtr.includes(Pag[x])) {
                tc++;
                pagtrx.splice(pagtrx.indexOf(Pag[x]), 1)
            }
        }
        score = Math.round(tc * (100 / Pag.length)) / 10;
        Say(ShowMonster(mon));
        Add("You walk " + Article(YourMonsters[mon], !1, "your") + " out into view. The judges quietly deliberate for a few moments.");
        oPag = Pag.slice();
        nextline = null;
        if (score < 9.9) {
            setTimeout(function () {
                LogLine(Article(YourMonsters[mon], !1, "Your") + " lost the pageant.");
                sendEvent('LostPageant', YourMonsters[mon] + ' = ' + oPag.join(','), prizemoney);
                Add("<span id='speech'>JUDGE: <span id='spoken'></span><span id='tospeak'></span></span>");
                JudgeSays = 'You have a fine monster. But sadly, we can only award you ' + score + ' points out of 10.';
                Typewrite(-1, JudgeSays);
                SaveGame();
                nextline = setInterval(function () {
                    if (talking) {} else {
                        Add("This contest has ended. Better luck next time.")
                        sound('bad');
                        Option("Question the judgement", "Dispute_" + mon);
                        Option("<Go home", "Ranch");
                        clearInterval(nextline)
                    }
                }, 200)
            }, 1700)
        } else {
            setTimeout(function () {
                LogLine(Article(YourMonsters[mon], !1, "Your") + " won the pageant. You got $" + prizetxt + ".");
                sendEvent('WonPageant', YourMonsters[mon] + ' = ' + oPag.join(','), prizemoney);
                Flags[mon] += "~P";
                Add("<span id='speech'>JUDGE: <span id='spoken'></span><span id='tospeak'></span></span>");
                JudgeSays = 'What a fantastic monster! 10 out of 10!'
                Typewrite(-1, JudgeSays);
                nextline = setInterval(function () {
                    if (talking) {} else {
                        Add(Article(YourMonsters[mon], !1, "Your") + " wins first place! You're awarded $" + prizetxt + ".")
                        Cash += prizemoney;
                        sound('m6');
                        Option("<Go home", "Ranch");
                        clearInterval(nextline)
                    }
                }, 200)
            }, 1700)
        }
        Pag = []
    }
    if (command.split("_")[0] == "Dispute") {
        mon = command.split("_")[1];
        Option();
        Say("<span id='speech'>JUDGE: <span id='spoken'></span><span id='tospeak'></span></span>");
        criteria = [];
        if (pagtrx.includes('aq')) criteria.push('lacking swimming ability');
        if (pagtrx.includes('fl')) criteria.push('lacking flying ability');
        if (pagtrx.includes('qt')) criteria.push('not quiet enough');
        if (pagtrx.includes('ld')) criteria.push('not loud enough');
        if (pagtrx.includes('wp')) criteria.push('lacking weapon skills');
        if (pagtrx.includes('bt')) criteria.push('lacking bite');
        if (pagtrx.includes('fr')) criteria.push('lacking flamethrowing ability');
        if (pagtrx.includes('dd')) criteria.push('not undead enough');
        if (pagtrx.includes('al')) criteria.push('without alien presence');
        if (pagtrx.includes('dm')) criteria.push('lacking demonic presence');
        if (pagtrx.includes('hy')) criteria.push('not hairy enough');
        if (pagtrx.includes('gr')) criteria.push('not green enough');
        if (pagtrx.includes('is')) criteria.push('not insectoid enough');
        if (pagtrx.includes('cy')) criteria.push('not very cuddly');
        if (pagtrx.includes('cb')) criteria.push('not cannibalistic enough');
        if (pagtrx.includes('ml')) criteria.push('lacking in legs');
        if (pagtrx.includes('ll')) criteria.push('excessively legged');
        if (pagtrx.includes('gc')) criteria.push('not gothic enough');
        if (pagtrx.includes('io')) criteria.push('too organic');
        if (pagtrx.includes('mc')) criteria.push('not mischievous enough');
        if (pagtrx.includes('ol')) criteria.push('too young');
        if (pagtrx.includes('sl')) criteria.push('too fast');
        if (pagtrx.includes('fs')) criteria.push('too slow');
        if (pagtrx.includes('tr')) criteria.push('too opaque');
        if (pagtrx.includes('sy')) criteria.push('too good-smelling');
        if (pagtrx.includes('fu')) criteria.push('not futuristic enough');
        if (pagtrx.includes('ss')) criteria.push('lacking shapeshifting ability');
        if (pagtrx.includes('it')) criteria.push('too unintelligent');
        if (pagtrx.includes('hl')) criteria.push('too hairy');
        if (pagtrx.includes('hu')) criteria.push('too inhuman');
        if (pagtrx.includes('sd')) criteria.push('lacking a tragic quality');
        if (pagtrx.includes('nc')) criteria.push('not nocturnal enough');
        if (pagtrx.includes('mg')) criteria.push('not cursed enough');
        if (pagtrx.includes('ct')) criteria.push('lacking clothes');
        if (pagtrx.includes('sh')) criteria.push('not amorphous enough');
        if (pagtrx.includes('my')) criteria.push('not mythological');
        if (pagtrx.includes('st')) criteria.push('too intelligent');
        if (pagtrx.includes('an')) criteria.push('lacking animal qualities');
        if (pagtrx.includes('sf')) criteria.push('lacking sci-fi elements');
        wcr = '';
        if (pagtrx.includes('sm') || pagtrx.includes('md') || pagtrx.includes('lg') || pagtrx.includes('hg')) {
            wcr = ('in the wrong weight class')
        }
        criteriatext = '';
        if (criteria.length == 1) criteriatext = criteria[0];
        else if (criteria.length == 2) criteriatext = criteria.join(' and ');
        else if (criteria.length >= 3) criteriatext = criteria.slice(0, -1).join(', ') + ', and ' + criteria.slice(-1);
        if (wcr != '') {
            if (criteria.length == 0) criteriatext += wcr;
            else if (criteria.length == 1) criteriatext += ' and ' + wcr;
            else if (criteria.length >= 2) criteriatext += '... not to mention ' + wcr
        }
        JudgeSays = "All scores are final. Unfortunately, we found " + Article(YourMonsters[mon], !1, "your") + " to be " + criteriatext + '.';
        Typewrite(-1, JudgeSays);
        Option("<Go home", "Ranch")
    }
    if (command == "Phone") {
        Option();
        callme = !1;
        callback = !1;
        Say("You answer the phone.");
        CallerName = Pick(['Abigail', 'Alexandra', 'Alison', 'Amanda', 'Amelia', 'Amy', 'Andrea', 'Angela', 'Anna', 'Anne', 'Audrey', 'Ava', 'Bella', 'Bernadette', 'Carol', 'Caroline', 'Carolyn', 'Chloe', 'Claire', 'Deirdre', 'Diana', 'Diane', 'Donna', 'Dorothy', 'Elizabeth', 'Ella', 'Emily', 'Emma', 'Faith', 'Felicity', 'Fiona', 'Gabrielle', 'Grace', 'Hannah', 'Heather', 'Irene', 'Jan', 'Jane', 'Jasmine', 'Jennifer', 'Jessica', 'Joan', 'Joanne', 'Julia', 'Karen', 'Katherine', 'Kimberly', 'Kylie', 'Lauren', 'Leah', 'Lillian', 'Lily', 'Lisa', 'Madeleine', 'Maria', 'Mary', 'Megan', 'Melanie', 'Michelle', 'Molly', 'Natalie', 'Nicola', 'Olivia', 'Penelope', 'Pippa', 'Rachel', 'Rebecca', 'Rose', 'Ruth', 'Sally', 'Samantha', 'Sarah', 'Sonia', 'Sophie', 'Stephanie', 'Sue', 'Theresa', 'Tracey', 'Una', 'Vanessa', 'Victoria', 'Virginia', 'Wanda', 'Wendy', 'Yvonne', 'Zoe', 'Adam', 'Adrian', 'Alan', 'Alexander', 'Andrew', 'Anthony', 'Austin', 'Benjamin', 'Blake', 'Boris', 'Brandon', 'Brian', 'Cameron', 'Carl', 'Charles', 'Christian', 'Christopher', 'Colin', 'Connor', 'Dan', 'David', 'Dominic', 'Dylan', 'Edward', 'Eric', 'Evan', 'Frank', 'Gavin', 'Gordon', 'Harry', 'Ian', 'Isaac', 'Jack', 'Jacob', 'Jake', 'James', 'Jason', 'Joe', 'John', 'Jonathan', 'Joseph', 'Joshua', 'Julian', 'Justin', 'Keith', 'Kevin', 'Leonard', 'Liam', 'Lucas', 'Luke', 'Matt', 'Max', 'Michael', 'Nathan', 'Neil', 'Nicholas', 'Oliver', 'Owen', 'Paul', 'Peter', 'Phil', 'Piers', 'Richard', 'Robert', 'Ryan', 'Sam', 'Sean', 'Sebastian', 'Simon', 'Stephen', 'Steven', 'Stewart', 'Thomas', 'Tim', 'Trevor', 'Victor', 'Warren', 'William']) + ' ' + Pick(['Night', 'Day', 'Moon', 'Sun', 'Jeg', 'Lid', 'Beet', 'Wheel', 'Oak', 'Brick', 'Tom', 'Pug', 'War', 'Milk', 'Tank', 'Ham', 'Fork', 'Goof', 'Plop', 'Lug', 'Beef', 'Reek', 'Mouth', 'Sham', 'Stug', 'Pum', 'Man', 'Sweet', 'Purp', 'Jort', 'Rick', 'Dark', 'Rum', 'Snack', 'Stack', 'Wis', 'Pomp', 'Rasp', 'Tud', 'Rat', 'Cran', 'Foul', 'Slap', 'Nor', 'Quattle', 'Winter', 'Summer', 'Cup', 'Snod', 'Rock', 'Jam', 'Bottle', 'Creed', 'Shed', 'Snap', 'Tarp', 'Clog', 'Fred', 'Snow', 'Car', 'Lamp']) + Pick(['marsh', 'brush', 'ler', 'ram', 'bug', 'bar', 'ford', 'kin', 'bit', 'hammer', 'wald', 'zer', 'weed', 'bert', 'leg', 'bean', 'ums', 'by', 'field', 'raham', 'son', 'pie', 'foot', 'agon', 'body', 'ster', 'house', 'ins', 'heart', 'ster', 'ola', 'onia', 'lord', 'ton', 'haver', 'cake', 'boy', 'thistle', 'thwait', 'us', 'smith', 'ly', 'sly', 'mond', 'frog', 'frond', 'mess', 'pack', 'pete', 'barth', 'task', 'musk', 'field', 'cast', 'aroni']);
        Add("<span id='speech'>" + CallerName.toUpperCase() + ": <span id='spoken'></span><span id='tospeak'></span></span>");
        CallerSays = '' + Pick(["Hi!", "Greetings!", "Hello!", "How are you?", "Hey there.", "Hello hello!"]) + " " + Pick(["I hear", "Word is", "I'm told", "Word on the street is", "The buzz is", "I've heard", "I'm hearing", "People are saying"]) + " that you're breeding some " + Pick(["cool", "fascinating", "groundbreaking", "exciting", "amazing", "innovative", "fantastic", "remarkable"]) + " new monster " + Pick(["mixes", "combos", "hybrids", "crossbreeds", "blends", "crosses"]) + ". Would you be interested in selling?";
        Typewrite(-1, CallerSays);
        Option("Yes, I'm selling", "Phone2");
        if (!Gear.includes('lc')) {
            copcall = Math.random() >= 0.95;
            if (Cash == 0) copcall = !1;
            Option("Are you a cop?", "Phone3")
        } else copcall = !1;
        Option("<No thanks", "Ranch")
    }
    if (command == "Phone3") {
        Option();
        killTimeouts();
        if (Chance(.40) && Cash > 0) {
            Say("You've offended the caller!");
            Add("<span id='speech'>" + CallerName.toUpperCase() + ": <span id='spoken'></span><span id='tospeak'></span></span>");
            Typewrite(-1, Pick(["Well, I never. Goodbye!", "Excuse me? Uh, bye.", "That's a weird question. Never mind.", "Uh, maybe I'll call back later.", "You know what, never mind."]));
            Option("<Okay", "Ranch")
        } else {
            Say("<span id='speech'>" + CallerName.toUpperCase() + ": <span id='spoken'></span><span id='tospeak'></span></span>");
            Typewrite(-1, Pick(["Nope!", "Ha, no.", "Definitely not!", "Don't worry, I'm not.", "I'd tell you if I was!", "No way.", "No!"]));
            copcall = !1;
            Option("Yes, I'm selling", "Phone2")
        }
        Tip("Some customers may be offended by this question, but at least it weeds out actual cops too. Not a bad idea as long as you're operating without a license.")
    }
    if (command == "Phone2") {
        if (!callback) {
            tWants = [];
            tfreq = 0;
            yourxbs = [];
            yourms = [];
            for (i = 0; i < YourMonsters.length; i++) {
                if (Parents[i] && !recentsales.includes(YourMonsters[i])) yourxbs.push(i);
                else if (!Parents[i] && !yourms.includes(YourMonsters[i])) yourms.push(YourMonsters[i])
            }
            par1 = '';
            par2 = '';
            pn = -1;
            dh = !1;
            if (Math.random() < .5 && yourms.length >= 2) {
                while (par1 == par2) {
                    par1 = Pick(yourms);
                    par2 = Pick(yourms)
                }
                px = Hybrid[ComboCheck(par1, par2)]
                dh = !0
            } else {
                pn = Pick(yourxbs);
                px = YourMonsters[pn];
                par1 = Monsters[Parents[pn].split(',')[0]];
                par2 = Monsters[Parents[pn].split(',')[1]]
            }
            hybridtraits = HybridizeTraits(par1, par2);
            whb = 0;
            tNum = 4;
            while (tWants.length < 4) {
                tWants.push(Pick(hybridtraits));
                tWants = tWants.filter(function (item, pos) {
                    return tWants.indexOf(item) == pos
                });
                tWants = tWants.filter(e => e !== 'md');
                if (tWants.length >= 4 && whb < 50) {
                    if (tWants.every(function (i) {
                            return GetTraits(par1).includes(i)
                        })) {
                        tWants = []
                    }
                    if (tWants.every(function (i) {
                            return GetTraits(par2).includes(i)
                        })) {
                        tWants = []
                    }
                }
                if (whb > 100) {
                    console.log('whb');
                    break
                }
                whb++
            }
            tWants = tWants.splice(0, tNum);
            tfreq = 1;
            for (i = 0; i < tWants.length; i++) {
                tfreq += (Traits.join(' ').split(tWants[i]).length - 1)
            }
            rr1 = GetTrait(par1, 'rr');
            rr2 = GetTrait(par2, 'rr');
            pool = yourxbs.length * 5;
            if (dh) pool = yourms.length * 5;
            offeramount = Math.floor(Math.max(pool + ((150 - tfreq) * 2) + (100 * (rr1 + rr2)) + (copcall * pool), 200));
            if ([par1, par2].includes('Shrek')) offeramount = (Math.floor(offeramount / 100) * 100) + 69;
            if (Flags[pn] && Flags[pn].indexOf("~P") > -1) offeramount *= 10;
            offerfraction = Math.floor(offeramount / 14);
            tries = 2
        }
        if (Previous == 'Ranch') cool = Pick(["Hello again!", "Hi again!", "Thanks for calling back!"]);
        else cool = Pick(['Great!', 'Excellent!', 'Wonderful!', 'Glad to hear it!', 'Perfect!', 'Cool!'])
        Say("<span id='speech'>" + CallerName.toUpperCase() + ": " + cool + " " + Pick(["Do you have any monsters that fit this description?", "I'm looking for a monster that fits this description...", "Here's what I'm looking for in a monster...", "Can you sell me a monster like this?"]) + "</span>");
        wantlist = '';
        for (i = 0; i < tWants.length; i++) {
            t = tWants[i];
            d = '';
            if (t == 'sm') d = Pick(['Small', 'Tiny', 'Miniature', 'Miniscule', 'On the small side', 'Little']);
            if (t == 'lg') d = Pick(['Large', 'Big', 'Sizable', 'Weighty', 'Bulky']);
            if (t == 'hg') d = Pick(['Huge', 'Humongous', 'Mammoth', 'Gigantic', 'Tremendous', 'Colossal', 'Gargantuan']);
            if (t == 'aq') d = Pick(['Aquatic', 'Marine', 'Water-based', 'Can swim']);
            if (t == 'fl') d = Pick(['Flying', 'Can fly', 'Aerial', 'Airborne']);
            if (t == 'qt') d = Pick(['Quiet', 'Low-volume']);
            if (t == 'ld') d = Pick(['Loud', 'Noisy']);
            if (t == 'wp') d = Pick(['Uses weapons', 'Weapon wielding']);
            if (t == 'bt') d = Pick(['Bites', 'Bites a lot', 'Will bite you']);
            if (t == 'fr') d = Pick(['Shoots fire', 'Shoots flames']);
            if (t == 'dd') d = 'Undead';
            if (t == 'al') d = Pick(['Alien', 'Extraterrestrial', 'From space']);
            if (t == 'dm') d = Pick(['Demonic', 'Hellish', 'Infernal']);
            if (t == 'hy') d = Pick(['Hairy', 'Furry']);
            if (t == 'gr') d = Pick(['Green', 'Green-skinned']);
            if (t == 'is') d = Pick(['Insectoid', 'Buglike']);
            if (t == 'cy') d = Pick(['Cuddly', 'Snuggly', 'Cute']);
            if (t == 'cb') d = 'Cannibalistic';
            if (t == 'ml') d = Pick(['Many-legged', 'Multipedal']);
            if (t == 'll') d = Pick(['No-legged', 'Legless']);
            if (t == 'gc') d = 'Gothic';
            if (t == 'io') d = Pick(['Inorganic', 'Manmade', 'Manufactured', 'Mass-produced']);
            if (t == 'mc') d = Pick(['Mischievous', 'Naughty', 'Rascally']);
            if (t == 'ol') d = Pick(['Old', 'Ancient', 'Historical']);
            if (t == 'sl') d = Pick(['Slow', 'Sluggish', 'Slow-moving']);
            if (t == 'fs') d = Pick(['Fast', 'Quick', 'High-speed', 'Speedy']);
            if (t == 'tr') d = Pick(['Translucent', 'Transparent', 'See-through']);
            if (t == 'sy') d = Pick(['Smelly', 'Odorous', 'Putrid', 'Rancid-smelling']);
            if (t == 'fu') d = 'Futuristic';
            if (t == 'ss') d = 'Shapeshifting';
            if (t == 'it') d = Pick(['Intelligent', 'Calculating', 'Cunning']);
            if (t == 'hl') d = Pick(['Hairless', 'Bald']);
            if (t == 'hu') d = 'Human';
            if (t == 'sd') d = Pick(['Sad', 'Mournful', 'Tragic', 'Depressed']);
            if (t == 'nc') d = Pick(['Nocturnal', 'Night-loving', 'Nightcrawling']);
            if (t == 'mg') d = Pick(['Magical', 'Cursed', 'Occult', 'Supernatural']);
            if (t == 'ct') d = Pick(['Clothed', 'Dressed', 'Attired']);
            if (t == 'sh') d = Pick(['Shapeless', 'Amorphous', 'Formless', 'nebulous']);
            if (t == 'my') d = Pick(['Mythological', 'Folkloric', 'Legendary']);
            if (t == 'st') d = Pick(['Stupid', 'Dimwitted', 'Unintelligent', 'Doltish']);
            if (t == 'an') d = Pick(['Animalian', 'Beastly', 'Bestial', 'Animal']);
            if (t == 'sf') d = Pick(['Sci-Fi', 'Science-fictiony']);
            wantlist += "• <span class='t_" + t + "'>" + d + "</span><br>"
        }
        if (Flags[pn] && Flags[pn].indexOf("~P") > -1) wantlist += "• Award-winning<br>";
        Add("<span id='speech'>" + wantlist.replace(/:..:/gi, '') + "</span>");
        Add("<span id='speech'>I'm willing to pay the market price of $" + offeramount + "!</span>");
        Tip("Hybrid monsters inherit traits from their parents. Some traits depend on whose body and head the monster has (for example, an aquatic body or an intelligent head.)<br>Callers' requests can always be met either with a hybrid you've bred or one you could create with monsters currently in your stables. If you haven't bred it yet, you can offer to call back later. It's up to you to figure out what monster they want.<br>Keeping more monsters in your stables results in more frequent calls with higher cash offers. However, if you try to sell the customer a monster they don't want, they'll lower their standing offer.");
        Option();
        CrossbreedList("Sell_");
        Option("Let me call you back", "CallYouBack");
        Option("<Sorry, can't help you", "HangUp")
    }
    if (command == "CallYouBack") {
        callback = !0;
        Act('Ranch')
    }
    if (command == "HangUp") {
        callback = !1;
        Act('Ranch')
    }
    if (command.split("_")[0] == "Sell") {
        mon = command.split("_")[1];
        Option();
        offertraits = HybridizeTraits(Monsters[Parents[mon].split(',')[0]], Monsters[Parents[mon].split(',')[1]]);
        if (tWants.every(function (i) {
                return offertraits.includes(i)
            })) {
            soldn = Article(YourMonsters[mon], !1, "A");
            callback = !1;
            Say("<span id='speech'>" + CallerName.toUpperCase() + ": <span id='spoken'></span><span id='tospeak'></span></span>");
            CallerSays = Pick([soldn + "? Sounds perfect!", soldn + " sounds just like what I'm looking for!", soldn + "! That's the monster for me!", "Wow! " + soldn + " sounds great!", soldn + "? I'll take it!"]);
            Typewrite(-1, CallerSays);
            nextline = null;
            if (copcall) {
                nextline = setInterval(function () {
                    if (talking) {} else {
                        oc = Math.min(Math.min(Math.max(Math.floor(Cash / 2), 1000), Cash), 50000);
                        Cash -= oc;
                        SaveGame();
                        sound('bad');
                        Add(CallerName + " comes by your ranch... and BUSTS YOU!");
                        Add("It was a sting operation! You've been fined $" + oc + " for breeding monsters without a license.");
                        Option("<Ouch!", "Ranch");
                        clearInterval(nextline)
                    }
                }, 200);
                sendEvent('Sting', '', oc)
            } else {
                nextline = setInterval(function () {
                    if (talking) {} else {
                        sound('m6');
                        Add(CallerName + " comes by your ranch and picks up the " + YourMonsters[mon].toUpperCase() + ".");
                        Add("You make $" + offeramount + "!");
                        recentsales.splice(0, 1);
                        recentsales.push(YourMonsters[mon]);
                        LogLine("Sold " + Article(YourMonsters[mon], !1) + " for $" + offeramount + ".");
                        LoseMonster(mon);
                        Cash += offeramount;
                        Option("<Okay", "Ranch");
                        clearInterval(nextline)
                    }
                }, 200);
                sendEvent('Sold', YourMonsters[mon], offeramount)
            }
        } else {
            sound('m3');
            if (tries > 0) {
                tries--;
                if (dh && tries == 0) nope = "If you haven't bred a monster like this yet, I can wait. " + Pick(["I'm sure what I'm asking for is possible.", "I'm really set on this.", "Maybe you can breed something like this."]);
                else {
                    nope = Pick(["Hmm. That doesn't sound quite like what I'm looking for.", "Not quite what I'm hoping for.", "No, that's not it.", "That doesn't sound right.", "Hmm. Not for me."]);
                    nope += " " + Pick(["What else you got?", "What else do you have?", "Any other ideas?", "Any other suggestions?", "Maybe something else?", "Let me go over that again."])
                }
                Say("<span id='speech'>" + nope + "</span>");
                owantlist = wantlist;
                for (var o = 0; o < tWants.length; o++) {
                    if (!offertraits.includes(tWants[o])) owantlist = owantlist.replace("t_" + tWants[o] + "'", "t_" + tWants[o] + "' style='font-style: italic'")
                }
                setTimeout(function () {
                    Add("<span id='speech'>" + owantlist + "</span>");
                    offeramount = Math.max(offeramount - offerfraction, 100);
                    Add("<span id='speech'>I'm willing to pay the market price of $" + offeramount + "!</span>");
                    CrossbreedList("Sell_");
                    Option("Let me call you back", "CallYouBack");
                    Option("<Sorry, can't help you", "Ranch")
                }, 1400)
            } else {
                Say("<span id='speech'>" + CallerName.toUpperCase() + ": <span id='spoken'></span><span id='tospeak'></span></span>");
                CallerSays = Pick(["Doesn't sound like you have what I'm looking for!", "I guess I'll look elsewhere!", "Well, thanks anyway.", "Maybe you'll have it some other time."]);
                Typewrite(-1, CallerSays);
                callback = !1;
                Option("<Sorry", "Ranch");
                sendEvent('Sold', 'FAILED TO SELL')
            }
        }
        newmenu = !1;
        Previous = 'Sell'
    }
    if (command.split("_")[0] == "SelectMonster") {
        Option();
        mon = command.split("_")[1];
        Say(ShowMonster(mon));
        HideMonsterImage();
        if (Flags[mon] && Flags[mon].indexOf("~P") > -1) {
            Add("<center>&#9733;&#9733;&#9733; <i>Monster Beauty Pageant Winner</i> &#9733;&#9733;&#9733;</center><br>")
        }
        if (Parents[mon]) {
            par1traits = Monsters[Parents[mon].split(',')[0]];
            par2traits = Monsters[Parents[mon].split(',')[1]];
            mt = HybridizeTraits(par1traits, par2traits)
        } else {
            mt = GetTraits(YourMonsters[mon])
        }
        d = [];
        if (mt.includes('sm')) d.push(Pick(['small', 'tiny', 'miniature', 'miniscule', 'on the small side', 'little']));
        if (mt.includes('lg')) d.push(Pick(['large', 'big', 'sizable', 'weighty', 'bulky']));
        if (mt.includes('hg')) d.push(Pick(['huge', 'humongous', 'mammoth', 'gigantic', 'tremendous', 'colossal', 'gargantuan']));
        if (mt.includes('aq')) d.push(Pick(['aquatic', 'marine']));
        if (mt.includes('fl')) d.push(Pick(['aerial', 'airborne']));
        if (mt.includes('qt')) d.push(Pick(['quiet', 'low-volume']));
        if (mt.includes('ld')) d.push(Pick(['loud', 'noisy']));
        if (mt.includes('wp')) d.push('weapon-wielding');
        if (mt.includes('bt')) d.push(Pick(['toothy', 'bitey']));
        if (mt.includes('fr')) d.push(Pick(['firey', 'flame-throwing']));
        if (mt.includes('dd')) d.push('undead');
        if (mt.includes('al')) d.push(Pick(['alien', 'extraterrestrial']));
        if (mt.includes('dm')) d.push(Pick(['demonic', 'hellish', 'infernal']));
        if (mt.includes('hy')) d.push(Pick(['hairy', 'furry', 'hirsute']));
        if (mt.includes('gr')) d.push(Pick(['green', 'green-skinned']));
        if (mt.includes('is')) d.push(Pick(['insectoid', 'buglike']));
        if (mt.includes('cy')) d.push(Pick(['cuddly', 'snuggly', 'cute']));
        if (mt.includes('cb')) d.push('cannibalistic');
        if (mt.includes('ml')) d.push(Pick(['many-legged', 'multipedal']));
        if (mt.includes('ll')) d.push(Pick(['no-legged', 'legless']));
        if (mt.includes('gc')) d.push('gothic');
        if (mt.includes('io')) d.push(Pick(['inorganic', 'manmade', 'manufactured', 'mass-produced']));
        if (mt.includes('mc')) d.push(Pick(['mischievous', 'naughty', 'rascally']));
        if (mt.includes('ol')) d.push(Pick(['old', 'ancient', 'historical']));
        if (mt.includes('sl')) d.push(Pick(['slow', 'sluggish', 'slow-moving']));
        if (mt.includes('fs')) d.push(Pick(['fast', 'quick', 'high-speed', 'speedy']));
        if (mt.includes('tr')) d.push(Pick(['translucent', 'transparent', 'see-through']));
        if (mt.includes('sy')) d.push(Pick(['smelly', 'odorous', 'putrid', 'rancid-smelling']));
        if (mt.includes('fu')) d.push('futuristic');
        if (mt.includes('ss')) d.push('shapeshifting');
        if (mt.includes('it')) d.push(Pick(['intelligent', 'calculating', 'cunning']));
        if (mt.includes('hl')) d.push(Pick(['hairless', 'bald']));
        if (mt.includes('hu')) d.push('human');
        if (mt.includes('sd')) d.push(Pick(['sad', 'mournful', 'tragic', 'depressed']));
        if (mt.includes('nc')) d.push(Pick(['nocturnal', 'night-loving', 'nightcrawling']));
        if (mt.includes('mg')) d.push(Pick(['magical', 'cursed', 'occult', 'supernatural']));
        if (mt.includes('ct')) d.push(Pick(['clothed', 'dressed', 'attired']));
        if (mt.includes('sh')) d.push(Pick(['shapeless', 'amorphous', 'formless', 'nebulous']));
        if (mt.includes('my')) d.push(Pick(['mythological', 'folkloric', 'legendary']));
        if (mt.includes('st')) d.push(Pick(['stupid', 'dimwitted', 'unintelligent', 'doltish']));
        if (mt.includes('an')) d.push(Pick(['animalian', 'beastly', 'bestial', 'animal']));
        if (mt.includes('sf')) d.push(Pick(['sci-fi', 'science-fictiony']));
        if (Parents[mon]) {
            Add(Article(YourMonsters[mon], !0, '这') + " 是一个 " + Pick(['让人害怕的', '幽灵般的', '令人毛骨悚然的', '恐怖的', '吓人的', '可怕的', '脊背发麻', '刺骨的']) + ", " + Pick(d) + " 杂交的 " + Article(Monsters[Parents[mon].split(',')[0]]) + " 和 " + Article(Monsters[Parents[mon].split(',')[1]]) + ". " + Pick(["哦啦啦!", "哇!", "哇哇!", "惊人!", "极好!", "奇妙!", "太棒了!", "漂亮!", "令人兴奋!", "了不起!", "不错!"]))
        } else {
            Add(Article(YourMonsters[mon], !0, '这') + " 是 " + Pick(["一个非常 ", "相当 ", "多么 ", "一个极其 ", "一个超级 ", "一个特别 ", "一个真的 ", "一个强烈 "]) + Pick(['让人害怕的', '幽灵般的', '令人毛骨悚然的', '恐怖的', '吓人的', '可怕的', '脊背发麻', '刺骨的']) + ", " + Pick(d) + " 怪物!");
            if (Flags[mon] && Flags[mon].indexOf("~B") > -1) Add("<br><small>" + Article(YourMonsters[mon], !0, '') + " 最近刚交配过。 该轮到其他一些怪物了！</small>");
            else Option("培育 " + Article(YourMonsters[mon], !1, 'the'), "Breed_" + [mon])
        }
        Option("交流跟 " + Article(YourMonsters[mon], !1, 'the'), "Talk_" + [mon]);
        Option("放生 " + Article(YourMonsters[mon], !1, 'the'), "Release_" + [mon]);
        Option("<返回", "List Monsters")
    }
    if (command.split("_")[0] == "Talk") {
        mon = command.split("_")[1];
        Say(ShowMonster(mon));
        HideMonsterImage();
        Add("<span id='speech'>" + YourMonsters[mon].toUpperCase() + ": <span id='spoken'></span><span id='tospeak'></span></span>");
        Typewrite(-1, MonsterTalk(YourMonsters[mon]));
        Option();
        Option("<Okay", Previous);
        sendEvent('Talk', YourMonsters[mon])
    }
    if (command.split("_")[0] == "Release") {
        mon = command.split("_")[1];
        Say("Are you sure you want to set " + Article(YourMonsters[mon], !0, 'this') + " free?");
        Option();
        Option("Yes", "Released_" + [mon]);
        Option("<No", Previous)
    }
    if (command.split("_")[0] == "Released") {
        mon = command.split("_")[1];
        Say(Pick(["Tearfully", "With a tear in your eye", "With a heavy heart", "Bittersweetly", "Wistfully"]) + ", you set " + Article(YourMonsters[mon], !0, 'the') + " free into the wilderness.");
        if (YourMonsters[mon] == 'Leprechaun') {
            Add("He throws you a gold coin. It's worth $100!");
            Cash += 100;
            sound('m6')
        }
        LogLine("Released " + Article(YourMonsters[mon], !1) + ".");
        sendEvent('Release', YourMonsters[mon]);
        LoseMonster(mon);
        Option();
        Option("<Back", "List Monsters")
    }
    if (command.split("_")[0] == "Breed") {
        Option();
        mon = command.split("_")[1];
        Say("Who should you breed " + Article(YourMonsters[mon], !0, 'this') + " with?");
        for (var i = 0; i < YourMonsters.length; i++) {
            if ((i != mon) && (!Parents[i])) {
                monstname = '';
                if (Bred[(ComboCheck(YourMonsters[mon], YourMonsters[i]))]) monstname += "&#10003; "
                else monstname += "• ";
                if (Flags[i] && Flags[i].indexOf("~B") > -1) monstname += "<i style='opacity: 0.5'>" + YourMonsters[i] + "</i>";
                else monstname += YourMonsters[i];
                Option(monstname, 'BreedWith_' + mon + "_" + i)
            }
        }
        Option("<Back", "SelectMonster_" + mon);
        Tip("Monsters who've mated too recently have darkened names.<br>Monsters who've already bred with this one have a checkmark. (However, if you breed them in the opposite order, you can get different-looking hybrids who inherit different traits.)")
    }
    if (command.split("_")[0] == "BreedWith") {
        mon1 = command.split("_")[1];
        mon2 = command.split("_")[2];
        Option();
        Main.innerHTML = '';
        samebreed = (YourMonsters[mon1] == YourMonsters[mon2]);
        NewHybrid = '';
        if (samebreed) NewHybrid = YourMonsters[mon1];
        else {
            hybridnum = ComboCheck(YourMonsters[mon1], YourMonsters[mon2]);
            NewHybrid = Hybrid[hybridnum].trim()
        }
        blob = null;
        blobfood = null;
        blobfull = 0;
        if ([YourMonsters[mon1], YourMonsters[mon2]].includes('Blob')) {
            if (YourMonsters[mon1] == 'Blob') {
                blob = mon1;
                blobfood = mon2
            } else {
                blob = mon2;
                blobfood = mon1
            }
            if (Flags[blob] && Flags[blob].indexOf('~e') > -1) {
                blobfull = parseInt((Flags[blob].substring(Flags[blob].indexOf('~e:') + 3, Flags[blob].indexOf(':e'))))
            }
        }
        if ((Flags[mon1] && Flags[mon1].indexOf("~B") > -1) || (Flags[mon2] && Flags[mon2].indexOf("~B") > -1)) {
            mb1 = (Flags[mon1] && Flags[mon1].indexOf("~B") > -1);
            mb2 = (Flags[mon2] && Flags[mon2].indexOf("~B") > -1);
            if (mb1 && mb2) Add(Article(YourMonsters[mon1], !0, 'The') + " and " + Article(YourMonsters[mon2], !0, 'the') + " have mated too recently!");
            else if (mb1) Add(Article(YourMonsters[mon1], !0, 'The') + " has mated too recently!");
            else if (mb2) {
                Add(Article(YourMonsters[mon2], !0, 'The') + " has mated too recently!");
                Option("Choose another mate", "Breed_" + mon1)
            }
            Option("<Back", "List Monsters")
        } else if (!NewHybrid || NewHybrid.length <= 1) {
            Add("You place " + Article(YourMonsters[mon1], !0, 'the') + " and " + Article(YourMonsters[mon2], !0, 'the') + " in the same pen, but they don't seem to want to mate.");
            Option("Choose another mate", "Breed_" + mon1);
            Option("<Back", "List Monsters")
        } else if ([YourMonsters[mon1], YourMonsters[mon2]].includes('Blob') && Chance(Math.max(.33 - (blobfull / 100), .0))) {
            Add("Oops! The BLOB " + Pick(['consumed ', 'absorbed ']) + Article(YourMonsters[blobfood], !0, 'the') + "!");
            Add("<span id='speech'>BLOB: <span id='spoken'></span><span id='tospeak'></span></span>");
            Typewrite(-1, MonsterTalk('Blob'));
            LogLine("Lost " + Article(YourMonsters[blobfood], !1) + ".");
            if (GetTrait(YourMonsters[blobfood], 'sm')) blobfull += 1;
            else if (GetTrait(YourMonsters[blobfood], 'md')) blobfull += 3;
            else if (GetTrait(YourMonsters[blobfood], 'lg')) blobfull += 10;
            else if (GetTrait(YourMonsters[blobfood], 'hg')) blobfull += 20;
            if (Flags[blob] && Flags[blob].indexOf('~e:') > -1) Flags[blob] = Flags[blob].replace(/~e:.*:e/, '~e:' + blobfull + ':e');
            else Flags[blob] += '~e:' + blobfull + ':e';
            LoseMonster(blobfood);
            Option("<Back", "List Monsters")
        } else {
            Add("It looks like " + Article(YourMonsters[mon1], !0, 'the') + " and " + Article(YourMonsters[mon2], !0, 'the') + " are mating! <span id='dots'>...</span>");
            Blink('dots', 4);
            setTimeout(function () {
                Add("They're done!")
            }, 2500);
            setTimeout(function () {
                Say("<center>Congratulations!<br>");
                Main.innerHTML += "<center>You've successfully bred " + Article(YourMonsters[mon1], !0, 'the') + " and " + Article(YourMonsters[mon2], !0, 'the') + " together.<br>Their child is a beautiful<br><a href='#' style='font-weight:bold; font-size:110%;' class='bluelink' onclick='Act(\"SelectMonster_" + (YourMonsters.length - 1) + "\"); return false;'>" + ShowMonster(YourMonsters.length - 1) + NewHybrid.toUpperCase() + "!</a></center>";
                HideMonsterImage();
                sound('m1');
                intent = encodeURIComponent(YourMonsters[mon1].toUpperCase() + " + " + YourMonsters[mon2].toUpperCase() + " = " + NewHybrid.toUpperCase() + "\n#MonsterBreeder MonsterBreeder.com").replace(/'/g, '%27');
                Main.innerHTML += "<p align='right'><small><small><a href='https://twitter.com/intent/tweet?text=" + intent + "' target='_blank'>tweet</a></small></small></p>";
                LogLine("Bred " + Article(YourMonsters[mon1], !1) + " and " + Article(YourMonsters[mon2], !1) + " for " + Article(NewHybrid, !1) + ".");
                sendEvent('Bred', NewHybrid, 0);
                hb = HybridsBred();
                if (hb == 99 || hb == 199 || hb == 299 || hb == 399 || hb == 499 || hb == 599 || hb == 699 || hb == 799 || hb == 899 || hb == Hybrid.length - 1) sendEvent('HybridMilestones', hb + 1);
                Option("<Back", "List Monsters")
            }, 3200);
            for (i = 0; i < Flags.length; i++) {
                if (Flags[i] && Flags[i].indexOf("~B") > -1) Flags[i] = Flags[i].replace("~B", "")
            }
            if (!Flags[mon1]) Flags[mon1] = '';
            if (!Flags[mon2]) Flags[mon2] = '';
            Flags[mon1] += "~B";
            Flags[mon2] += "~B";
            YourMonsters.push(NewHybrid);
            if (!samebreed) {
                Bred[hybridnum] = '1';
                Parents[YourMonsters.length - 1] = Monsters.indexOf(YourMonsters[mon1]) + "," + Monsters.indexOf(YourMonsters[mon2])
            }
            callme = !0
        }
    }
    if (command.split("_")[0] == "Capture") {
        Option();
        mon = command.split("_")[1];
        if (GetTrait(Monsters[mon], 'aq') && !Gear.includes('aq')) {
            sound('m3');
            Say(Article(Monsters[mon], !0, 'The') + " swims away! You need specialty aquatic monster-catching gear.");
            Option("Continue exploring", Previous)
        } else if (GetTrait(Monsters[mon], 'fl') && !Gear.includes('fl')) {
            sound('m3');
            Say(Article(Monsters[mon], !0, 'The') + " flies away! You need specialty aerial monster-catching gear.");
            Option("Continue exploring", Previous)
        } else if (Weight(mon) + Weight(TruckMonsters) > TruckCap) {
            sound('m3');
            Say("Your truck doesn't have enough room for " + Article(Monsters[mon], !0) + "!");
            if (TruckCap <= 9) Tip("Monsters come in four sizes: small, medium, large, and humongous. Your starter truck can only fit small and medium monsters. Bigger trucks can be purchased from the monster catalog. If your truck is full, simply return to your ranch to unload.");
            else Tip("Monsters come in four sizes: small, medium, large, and humongous. If your truck is full, simply return to your ranch to unload.");
            Option("Continue exploring", Previous)
        } else {
            sound('m2');
            Say(ShowMonster(-1, mon));
            HideMonsterImage();
            Add("You " + Pick(['successfully', 'are able to', 'easily', 'manage to', 'artfully', 'just barely', 'skillfully', 'deftly']) + " " + Pick(['capture', 'catch', 'nab', 'obtain', 'acquire', 'ensnare', 'bag', 'snap up', 'wrangle']) + " " + Article(Monsters[mon], !0, 'the') + "!");
            TruckMonsters.push(parseInt(mon));
            LogLine("Captured " + Article(Monsters[mon], !1, 'a') + ".");
            sendEvent('Captured', Monsters[mon], 0);
            newmenu = !1;
            Add("<span id='speech'>" + Monsters[mon].toUpperCase() + ": <span id='spoken'></span><span id='tospeak'></span></span>");
            Typewrite(-1, MonsterTalk(Monsters[mon]));
            Option("Put " + Article(Monsters[mon], !1, 'the') + " in your truck", "PutInTruck_" + mon)
        }
    }
    if (command.split("_")[0] == "PutInTruck") {
        Option();
        mon = command.split("_")[1];
        Say("You secure " + Article(Monsters[mon], !0, 'the') + " in the back of your truck.");
        Add("Your truck is " + Math.floor((Weight(TruckMonsters) / TruckCap) * 100) + "% full.");
        Option("Continue exploring", Previous);
        Option("<Drive back to the ranch", "Ranch")
    }
    if (command == "Travel") {
        Main.innerHTML = '';
        ShowDriveMap(command);
        if (Previous == 'Ranch') {
            sound('m4');
            if (YourMonsters[0] == '0') Add("Exploring local hotspots is a great way to find and capture wild monsters.");
            Add("You load up your gear into your truck.")
        }
        Add("To the north are THE WOODS.");
        Add("To the east is THE CITY.");
        Add("To the south is THE DESERT.");
        Option();
        Option("Drive to the woods", "Woods");
        Option("Drive to the city", "City");
        Option("Drive to the desert", "Desert");
        Option("<Back", "Ranch")
    }
    if (command == "Woods") {
        Main.innerHTML = '';
        ShowDriveMap(command);
        if (Previous == 'Travel' || Previous == 'Castle') {
            Add("You drive to the edge of the dark woods. There's a narrow path leading in.");
            Add("To the west is a CASTLE.")
        } else if (Previous == "WoodsEx") Add("You exit the woods and return to your truck.");
        else if (Previous == "GraveyardEx") Add("You hike back through the woods and return to your truck.");
        Option();
        Option("~Explore the woods", "WoodsEx");
        Option("Drive to the castle", "Castle");
        Option("<Drive back to the ranch", "Ranch")
    }
    if (command == "Castle") {
        Main.innerHTML = '';
        ShowDriveMap(command);
        if (Previous == 'Woods') {
            Add("You drive toward the ancient stone CASTLE. Its shape seems to blacken as a thunderstorm gathers overhead.");
            Add("To the east are THE WOODS.")
        } else Add("You exit the castle and return to your truck.");
        Option();
        Option("~Explore the castle", "CastleEx");
        Option("Drive to the woods", "Woods");
        Option("<Drive back to the ranch", "Ranch")
    }
    if (command == "City") {
        Main.innerHTML = '';
        ShowDriveMap(command);
        if (Previous == "Travel" || Previous == "Suburbs") {
            Add("You drive to THE CITY. If you can find parking, there are plenty of monsters to encounter here.");
            Add("To the north are THE SUBURBS.")
        } else if (Previous = 'SuburbsEx') Add("You return to your truck.");
        else if (Previous = 'LabEx') Add("You exit the lab and return to your truck.");
        Option();
        Option("~Explore the city", "CityEx");
        Option("Drive to the suburbs", "Suburbs");
        Option("<Drive back to the ranch", "Ranch")
    }
    if (command == "Suburbs") {
        Main.innerHTML = '';
        ShowDriveMap(command);
        if (Previous == "City") {
            Add("You drive through the nearby SUBURBS, a sleepy, unassuming domestic quarter.");
            Add("To the south is THE CITY.")
        } else if (Previous = 'SuburbsEx') Add("You return to your truck.");
        else if (Previous = 'HouseEx') Add("You leave the creepy old house and return to your truck.");
        Option();
        Option("~Explore the suburbs", "SuburbsEx");
        Option("Drive to the city", "City");
        Option("<Drive back to the ranch", "Ranch")
    }
    if (command == "Desert") {
        Main.innerHTML = '';
        ShowDriveMap(command);
        if (Previous == 'Travel' || Previous == 'Lake') {
            Add("You drive into THE DESERT. It stretches on seemingly forever.");
            Add("To the west is THE LAKE.")
        } else if (Previous == 'DesertEx') Add("You trek back through the desert to your truck.");
        else if (Previous == 'CaveEx') Add("You find your way out of the cave and make your way back to your truck.");
        else if (Previous == 'HellEx') Add("You backtrack through the labyrinth and cave, and return to your truck.");
        Option();
        Option("~Explore the desert", "DesertEx");
        Option("Drive to the lake", "Lake");
        Option("<Drive back to the ranch", "Ranch")
    }
    if (command == "Lake") {
        Main.innerHTML = '';
        ShowDriveMap(command);
        if (Previous == 'Desert') {
            Add("You drive to the serene, still LAKE.");
            Add("To the east is THE DESERT.")
        } else Add("You return to your truck.");
        Option();
        Option("~Explore the lake", "LakeEx");
        Option("Drive to the desert", "Desert");
        Option("<Drive back to the ranch", "Ranch")
    }
    if (command == "WoodsEx") Explore(mWoods, "Woods", 2, 11, "GraveyardEx", 12, 8);
    if (command == "GraveyardEx") Explore(mGraveyard, "Woods", 0, 8, "WoodsEx", 0, 8);
    if (command == "SuburbsEx") Explore(mSuburbs, "Suburbs", 1, 10, "HouseEx", 6, 1);
    if (command == "HouseEx") Explore(mHouse, "Suburbs", 8, 10, "SuburbsEx", 8, 10);
    if (command == "CityEx") Explore(mCity, "City", 1, 6, "LabEx", 10, 4);
    if (command == "LabEx") Explore(mLab, "City", 6, 0, "CityEx", 6, 0);
    if (command == "LakeEx") Explore(mLake, "Lake", 10, 6);
    if (command == "CastleEx") Explore(mCastle, "Castle", 7, 13);
    if (command == "DesertEx") Explore(mDesert, "Desert", 6, 0, "CaveEx", 11, 12);
    if (command == "CaveEx") {
        if (Previous == "HellEx") Explore(mCave, "Desert", 7, 0, "HellEx", 1, 13);
        else Explore(mCave, "Desert", 7, 0, "DesertEx", 7, 0)
    }
    if (command == "HellEx") Explore(mHell, "Desert", 7, 0, "CaveEx", 7, 0);
    if (command == "Pull the book") {
        newmenu = !1;
        Main.innerHTML = '';
        bx = 4;
        by = 5;
        currentmap[by] = currentmap[by].substring(0, bx) + '2' + currentmap[by].substring(bx + 1);
        ShowNav(currentmap);
        Add("You pull the book. The bookshelf slides open, revealing a secret passageway!");
        sound('m5');
        document.getElementById("Pull the book").remove()
    }
    if (command == "Pull the candlestick") {
        newmenu = !1;
        Main.innerHTML = '';
        bx = 10;
        by = 5;
        currentmap[by] = currentmap[by].substring(0, bx) + '2' + currentmap[by].substring(bx + 1);
        ShowNav(currentmap);
        Add("You pull the candlestick. The fireplace swivels open, revealing a secret passageway!");
        sound('m5');
        document.getElementById("Pull the candlestick").remove()
    }
    if (command == "Push the rock") {
        newmenu = !1;
        Main.innerHTML = '';
        bx = 3;
        by = 1;
        currentmap[by] = currentmap[by].substring(0, bx) + '2' + currentmap[by].substring(bx + 1);
        ShowNav(currentmap);
        Add("You shove the rock aside, exposing a small pathway.");
        sound('m5');
        document.getElementById("Push the rock").remove()
    }
    if (newmenu) Previous = command
}

function Explore(where, mainloc, mx, my, subloc = -1, sx = -1, sy = -1) {
    randomloop(mwalks, 1);
    Main.innerHTML = '';
    Option();
    currentmap = where;
    if (Previous == mainloc) {
        X = mx;
        Y = my
    } else if (Previous == subloc) {
        X = sx;
        Y = sy
    }
    ShowNav(currentmap);
    if (where == mWoods) {
        if (Previous == mainloc) Add("You park your truck outside the woods and venture in, hauling along your monster-catching gear.");
        else if (Previous == subloc) {
            Add("You pass through the bridge into the spooky woods.");
            Option("~Cross bridge", "GraveyardEx");
            MarkMap('E')
        } else {
            if (TextZone("11,8 = There's a covered bridge to the east."));
            if (MonsterZone(19, .20, [10, 5], "There's a swampy pool of water here.", "Something bubbles up from the water...")) {
                MonsterZone(43, .02, [10, 5], "", "A green figure appears before you...")
            } else if (MonsterZone(17, .20, [7, 1], "You see strange, long grooves in the jungle floor.", "Something uncoils before you...")) {} else if (MonsterZone([12, 32], .10, [6, 1, 11, 4], "You're in a humid, jungle-like section of the woods.", "Something leaps out at you.")) {
                MonsterZone(11, .01, -1, "", "You hear very loud stomping.")
            } else if (MonsterZone(9, .20, [7, 7], "You're in a small clearing. The full moon shines brightly through the treetops.", "A howling cuts through the night.")) {} else if (MonsterZone(24, .20, [2, 2], "There's an abandoned campsite here. An old tent is ripped to shreds.", "You hear a twig snap...")) {} else if (MonsterZone(22, .10, [12, 8], "You're on a covered bridge.", "Something gallops up behind you...")) {
                Option("~Cross bridge", "GraveyardEx");
                MarkMap('E')
            } else {
                MonsterZone([5, 18, 38], .05, -1, "", "Something's lurking in the trees...")
            }
            if (Main.innerHTML.indexOf('<p>') == -1) Add("You're wandering the dark woods.")
        }
    }
    if (where == mGraveyard) {
        if (Previous == subloc) {
            sound('m5');
            Add("You pass through the bridge. On the other side there's an old graveyard.");
            Option("~Cross bridge", "WoodsEx");
            MarkMap('E')
        } else {
            if (TextZone("1,1 = There's a gravestone from the 1800s here with fresh flowers on it.")) {} else if (TextZone("5,4 = There's a freshly dug grave here. There's no one in it yet.")) {} else if (TextZone("8,6 = There's a gravestone here that just reads \"YOU\". It's not funny.")) {} else if (TextZone("10,10 = There's a gravestone here that's been vandalized repeatedly.")) {} else if (!InZone(10, 1) && TextZone("1,1,10,5 = You're on a hilly path, winding through very old gravestones.")) {} else if (TextZone("7,6,10,10 = You're on a hilly path, winding through very old gravestones.")) {} else if (TextZone("1,6,6,10 = You're in a small cemetery. The gravestones here are crumbling.")) {}
            if (MonsterZone(22, .33, [0, 8], "You're in a covered bridge.", "Something gallops up behind you...")) {
                Option("~Cross bridge", "WoodsEx");
                MarkMap('E')
            } else if (MonsterZone(7, .20, [10, 1], "There's a pyramid-shaped tomb here.", "A stone door slides open.")) {} else if (MonsterZone([6, 21], .04, -1, "", "Something crawls up from the dirt...")) {
                MonsterZone(3, .02, -1, "", "A figure materializes...");
                MonsterZone(47, .02, -1, "", "You hear raspy laughter...")
            }
        }
    }
    if (where == mCity) {
        if (Previous == mainloc) Add("You park your truck and bring your monster-catching gear out into the city.");
        else if (Previous == subloc) {
            Add("You exit the science lab.");
            Option("~Enter the building", "LabEx");
            MarkMap('E')
        } else {
            if (MonsterZone(29, .3, [3, 9], "There's a very fancy restaurant here.", "Someone sneaks up on you...")) {} else if (MonsterZone(11, .05, [5, 3], "You're at the foot of a large, art deco skyscraper.", "Something leaps down from the tower...")) {
                MonsterZone(48, .05, -1, "", "You smell a sweet vanilla scent...")
            } else if (MonsterZone(2, .10, [12, 10, 12, 11], "You're on a pier. It smells like fish.", "Something jumps out from the ocean!")) {
                MonsterZone([10, 46], .05, -1, "", "Something emerges from the ocean!")
            } else if (InZone([10, 4])) {
                Add("You're near the entrance to a high-tech scientific research building.");
                Option("~Enter the building", "LabEx");
                MarkMap('E')
            } else {
                if (TextZone("1,1 = You're at the corner of Torpor and Cello.")) {} else if (TextZone("1,6 = You're at the intersection of Torpor and Mint.")) {} else if (TextZone("1,11 = You're at the corner of Torpor and Heyday.")) {} else if (TextZone("7,1 = You're at the intersection of Cello and Button.")) {} else if (TextZone("3,8,5,10 = You're on Step Street.")) {} else if (TextZone("7,6 = You're at the intersection of Button and Mint.")) {} else if (TextZone("7,11 = You're at the intersection of Button and Heyday.")) {} else if (TextZone("5,11 = You're at the intersection of Heyday and Step.")) {} else if (TextZone("12,9 = You're at the corner of Crier and Heyday. There's a pier to the south.")) {} else if (TextZone("8,9 = You're in a cold alley.")) {} else if (TextZone("8,4 = You're in a filthy alley.")) {} else if (TextZone("10,7 = You're in a normal alley.")) {} else if (TextZone("3,2,3,4 = You're on Window Street.")) {} else if (TextZone("3,1 = You're at the intersection of Cello and Window.")) {} else if (TextZone("12,1 = You're at the corner of Cello and Crier.")) {} else if (TextZone("12,6 = You're at the intersection of Mint and Crier.")) {} else if (TextZone("10,2,10,3 = You're on Vision Street.")) {} else if (TextZone("10,1 = You're at the intersection of Cello and Vision.")) {} else if (TextZone("5,4,5,5 = You're on Beauty Street.")) {} else if (TextZone("5,6 = You're at the intersection of Mint and Beauty.")) {} else if (TextZone("12,2,12,8 = You're on Crier Drive.")) {} else if (TextZone("7,2,7,10 = You're on Button Street.")) {} else if (TextZone("1,2,1,10 = You're on Torpor Street.")) {} else if (TextZone("2,1,11,1 = You're on Cello Street.")) {} else if (TextZone("2,6,11,6 = You're on Mint Avenue.")) {} else if (TextZone("2,11,10,11 = You're on Heyday Street.")) {} else if (TextZone("10,9,11,10 = You're on Heyday Street.")) {}
                MonsterZone([33, 35, 39], .05, -1, "", "Something emerges from a dark corner...");
                MonsterZone(0, .02, -1, "", "Something claws at your feet...");
                if (!document.getElementById("encounter") && Chance(.11)) {
                    Add(Pick(["You pass some shady looking teens.", "There's an idling police car nearby.", "Something knocks against a trash can.", "Some businessmen pass by.", "You hear sirens in the distance.", "There's broken glass on the ground.", "You hear a subway train rumbling underground.", "A rat scampers past you.", "An old man stares silently at you."]))
                }
            }
            if (Main.innerHTML.indexOf('<p>') == -1) Add("You're walking the streets of the city.")
        }
    }
    if (where == mLab) {
        if (Previous == subloc) {
            sound('m5');
            Add("You enter the science lab. There don't seem to be any security guards. An alarm is sounding.");
            Option("~Exit the building", "CityEx");
            MarkMap('E')
        } else {
            if (TextZone("6,0 = You're at the entrance of the building.")) {
                Option("~Exit the building", "CityEx");
                MarkMap('E')
            } else if (TextZone("6,0,6,5 = You're in a long central hallway.")) {} else if (TextZone("1,1,9,1 = You're in a side hallway.")) {} else if (TextZone("1,2,1,8 = You're in a long corridor. Caution signs line the walls.")) {}
            if (TextZone("3,6,9,6 = You're in an observation room.")) {}
            if (TextZone("4,7,8,7 = You're looking through a glass viewport into a containment room. You don't see anyone on the other side.")) {}
            if (MonsterZone(31, .15, [8, 3, 9, 4], "You're in an autopsy room. It's overrun with strange pods.", "Something descends from the drop ceiling!")) {} else if (MonsterZone(35, .15, [3, 3, 4, 4], "You're in a robotics lab. It's been trashed.", "Something smashes through the wall!")) {} else if (TextZone("1,9,9,10 = You're in some sort of containment room. The back wall is lined with steel doors of various sizes.")) {
                MonsterZone([6, 15, 25, 37], .20, -1, "", "A door swings open...");
                MonsterZone(36, .003, -1, "", "A door swings open...")
            }
        }
    }
    if (where == mSuburbs) {
        if (Previous == mainloc) Add("You unpack your monster-catching gear from your truck and begin to explore the suburban neighborhood.");
        else {
            if (TextZone("1,1,11,5 = You're on a large cul-de-sac.")) {}
            if (TextZone("2,10,10,10 = You're on Oak Street.")) {}
            if (TextZone("2,8,10,8 = You're on Pine Street.")) {}
            if (TextZone("2,6,10,6 = You're on Elm Street.")) {}
            if (TextZone("1,6,1,10 = You're on Cedar Street.")) {}
            if (TextZone("11,6,11,9 = You're on Birch Street.")) {}
            if (TextZone("4,7,8,7 = You're on a small cross street.")) {}
            if (TextZone("4,9,8,9 = You're on a small cross street.")) {}
            if (InZone(6, 1, 6, 1)) {
                Add("Sticking out like a sore thumb, a large deteriorating OLD HOUSE stands before you.");
                MarkMap('E');
                Option("~Enter the house", "HouseEx")
            } else if (MonsterZone(16, .25, [4, 9], "There's a dark, dank storm drain nearby.", "You hear something from below...")) {} else if (MonsterZone(25, .10, [11, 10], "On the corner lot, a derelict 1950's movie theater still stands.", "A shape oozes into view...")) {} else if (MonsterZone(23, .10, [2, 6, 10, 6], "", "A dreamlike state washes over you...")) {} else MonsterZone([0, 9, 30, 33], .05, -1);
            if (Main.innerHTML.indexOf('<p>') == -1) Add("You're roaming through the suburbs.")
        }
    }
    if (where == mHouse) {
        if (Previous == subloc) {
            sound('m5');
            Add("You enter the creepy old house. The door slams itself behind you!<br>Luckily it's not locked.");
            MarkMap('E');
            Option("~Exit the house", "SuburbsEx")
        } else {
            if (TextZone("7,8,9,9 = You're in a musty foyer."));
            else if (TextZone("4,6,6,8 = You're in what was once a living room."));
            else if (TextZone("1,6,2,8 = You're in a study. Torn books and papers line the floor."));
            else if (TextZone("4,2,5,4 = You're in a dining room. The dining table is missing legs."));
            else if (TextZone("1,2,2,4 = You're in a ransacked kitchen. The sink is clogged and full of green water."));
            if (MonsterZone(27, .20, [10, 1, 11, 2], "You're in a child's bedroom. It hasn't been inhabited in quite some time.", "Something dashes out from under the bed...!")) {} else if (MonsterZone(45, .05, [7, 1, 8, 2], "You're in a dusty bedroom. The windows are broken.", "Something pins you to the bed!")) {} else if (MonsterZone(44, .10, [9, 6, 10, 7], "You're in a disgusting bathroom.", "Someone's in here with you...")) {} else if (InZone([8, 10])) {
                Add("You're in the entranceway to the old house. The door is nearly rotting off the hinges.");
                MarkMap('E');
                Option("~Exit the house", "SuburbsEx")
            } else {
                MonsterZone([0, 3], .06, -1, "", "Something's following you...");
                MonsterZone(47, .02, -1, "", "There's a sudden flash of black and white stripes...")
            }
        }
    }
    if (where == mCastle) {
        if (Previous == mainloc) Add("You leave your truck in front and step toward the castle, bringing along your monster-catching gear.");
        else {
            if (TextZone("1,5,2,8 = You're on a large spiral staircase."));
            if (TextZone("12,5,13,8 = You're on a large spiral staircase."));
            if (TextZone("4,2,10,2 = You're in a candlelit hallway lined with stained glass windows."));
            if (TextZone("5,9,9,10 = You're in a dusty sitting room. The walls are decorated by gray, distorted paintings."));
            if (TextZone("7,11 = You're passing through the castle's stone entranceway."));
            if (TextZone("3,5,4,5 = You're in a narrow secret passageway."));
            if (TextZone("10,5,11,5 = You're in a narrow secret passageway."));
            if (TextZone("7,12,7,13 = You're on a tremendous wooden drawbridge."));
            if (InZone(5, 5) && Pos(mCastle, 4, 5) < 3) {
                Add("You're in a library.<br>There's a book sticking conspicuously out of its shelf here.");
                Option("Pull the book", "Pull the book")
            } else if (TextZone("5,4,6,7 = You're in a library. The books are packed into shelves two stories high. Occasionally, a book seems to move."));
            if (InZone(9, 5) && Pos(mCastle, 10, 5) < 3) {
                Add("You're in a dining room.<br>There's a fireplace here. A candlestick next to it juts out conspicuously.");
                Option("Pull the candlestick", "Pull the candlestick")
            } else if (TextZone("8,4,9,7 = You're in a dining room. There's a sprawling, empty dining table, but no chairs."));
            if (InZone(1, 12, 6, 13) || InZone(8, 12, 13, 13)) {
                Add("You're walking along the castle moat. The water looks filthy.");
                MonsterZone(8, .06, -1, "", "Something is emerging from the moat...")
            } else if (MonsterZone(20, .10, [1, 1, 3, 3], "You're in the northwest spire. The bricks here are crumbling.", "Outside, something soars toward the window..."));
            else if (MonsterZone(14, .10, [11, 1, 13, 3], "You're in the northeast spire. There's an ornate coffin here.", "Something flutters in and transforms before your eyes!"));
            else if (MonsterZone(15, .15, [1, 9, 3, 10], "You're in a dungeon. There are large, broken shackles on the wall.", "You hear boots stomping heavily. You turn around..."));
            else if (MonsterZone(21, .15, [11, 9, 13, 10], "You're in a dungeon. Various bones are scattered about the floor.", "Something pops up from the corner..."));
            else if (InZone(1, 1, 13, 11)) {
                MonsterZone(3, .05, -1, "", "You hear moaning...");
                MonsterZone(41, .008, -1, "", "You hear jaunty flute music...")
            }
        }
    }
    if (where == mLake) {
        if (Previous == mainloc) Add("You leave your truck by the lake and begin circling the shore, carrying along your monster-catching gear.");
        else {
            if (TextZone("1,2,3,10 = You're on the west side of the lake.")) {} else if (TextZone("2,1,8,3 = You're on the north side of the lake.")) {} else if (TextZone("8,2,10,8 = You're on the east side of the lake.")) {} else if (TextZone("1,9,9,11 = You're on the south side of the lake.")) {}
            if (TextZone("3,5 = There are some discarded sandals here.")) {}
            if (TextZone("1,10 = There's a small inlet here with tiny fish swimming around.")) {}
            if (TextZone("7,9 = There's a dark blue hue to the water here.")) {}
            if (TextZone("9,4 = There's \"NO SWIMMING\" sign here.")) {}
            if (MonsterZone(24, .10, [7, 1], "There's a rotting old rowboat here.", "Something comes out of the woods behind you...")) {} else if (MonsterZone([2, 8, 19], .06, -1, "", "Something is " + Pick(['coming out of', 'rising out of', 'emerging from', 'splashing in', 'surfacing from']) + " the water...")) {
                MonsterZone(4, .01, -1, "", "Something is " + Pick(['coming out of', 'rising out of', 'emerging from', 'splashing in', 'surfacing from']) + " the water...");
                MonsterZone(10, .005, -1, "", "Something is " + Pick(['coming out of', 'rising out of', 'emerging from', 'splashing in', 'surfacing from']) + " the water...");
                MonsterZone(46, .005, -1, "", "Something is " + Pick(['coming out of', 'rising out of', 'emerging from', 'splashing in', 'surfacing from']) + " the water...")
            }
        }
    }
    if (where == mDesert) {
        if (Previous == mainloc) {
            Add("You step out of your truck into the sprawling desert, monster-catching gear in tow.");
            tx = (2 + Math.floor(Math.random() * 9));
            ty = (1 + Math.floor(Math.random() * 9));
            tc = 0;
            w2 = ''
        } else {
            if (InZone([11, 12])) {
                if (Previous == subloc) Add("You exit the cave and step out into the desert.");
                else Add("There's a cave opening here. You hear strange sounds coming from within.");
                Option("~Enter the cave", "CaveEx");
                MarkMap('E')
            } else if (MonsterZone(26, .20, [0, 3], "There's an old rundown house here. It smells of rotting meat.", "You hear a buzzing noise...")) {} else {
                if (InZone([tx, ty])) {
                    if (tc == 13) {
                        tx = -1;
                        ty = -1;
                        sound(Pick(['scare1', 'scare2', 'scare3', 'scare4']));
                        Add("<span id='encounter'>Oh no! It's a TORNADO!</span>");
                        Blink('encounter', 3);
                        Option("~Capture the Tornado", "Capture_42")
                    } else {
                        winddir = [];
                        if (w2 != 'n' && ty < 9 && Pos(mDesert, tx, ty + 1) > 1) winddir.push('s');
                        if (w2 != 's' && ty > 1 && Pos(mDesert, tx, ty - 1) > 1) winddir.push('n');
                        if (w2 != 'w' && tx < 10 && Pos(mDesert, tx + 1, ty) > 1) winddir.push('e');
                        if (w2 != 'e' && tx > 2 && Pos(mDesert, tx - 1, ty) > 1) winddir.push('w');
                        w = Pick(winddir);
                        w2 = w;
                        if (tc < 1) word = "gentle";
                        else if (tc < 3) word = "slight";
                        else if (tc < 5) word = "modest";
                        else if (tc < 7) word = "steady";
                        else if (tc < 9) word = "strong";
                        else if (tc < 11) word = "blustery";
                        else if (tc < 12) word = "turbulent";
                        else if (tc < 13) word = "violent";
                        if (w == 'n') {
                            Add("There's a " + word + " wind coming from the north.");
                            ty--
                        } else if (w == 's') {
                            Add("There's a " + word + " wind coming from the south.");
                            ty++
                        } else if (w == 'e') {
                            Add("There's a " + word + " wind coming from the east.");
                            tx++
                        } else if (w == 'w') {
                            Add("There's a " + word + " wind coming from the west.");
                            tx--
                        }
                        tc++
                    }
                } else {
                    if (w2 != '') {
                        tc = 0;
                        tx = X;
                        ty = Y;
                        while (tx == X && ty == Y) {
                            tx = (2 + Math.floor(Math.random() * 9));
                            ty = (1 + Math.floor(Math.random() * 9));
                            w2 = ''
                        }
                    }
                    MonsterZone([1, 7, 12, 21], .04, -1, "", "Something emerges from the dust...");
                    MonsterZone(34, .005, -1, "", "You hear something huge crawling toward you...")
                }
            }
            if (Main.innerHTML.indexOf('<p>') == -1) Add("You're wandering through the desert.")
        }
    }
    if (where == mCave) {
        if (Previous == 'DesertEx') {
            sound('m5');
            Add("You turn on your flashlight and enter the dark cave.");
            Option("~Exit the cave", "DesertEx");
            MarkMap('E')
        } else if (Previous == 'HellEx') {
            Option("~Enter the crevice", "HellEx");
            MarkMap('E');
            Add("You escape from the burning labyrinth into the cool, dark cave.")
        } else {
            if (InZone(2, 1) && Pos(mCave, 3, 1) < 3) {
                Add("There's a loose rock covering something here.");
                Option("Push the rock", "Push the rock")
            } else if (InZone([7, 0])) {
                Add("The cave exits into the desert here.");
                Option("~Exit the cave", "DesertEx");
                MarkMap('E')
            } else if (InZone([1, 13])) {
                Add("There's a crevice in the wall here just big enough to fit through. A hot, red glow emanates from within.");
                Option("~Enter the crevice", "HellEx");
                MarkMap('E')
            } else if (MonsterZone(43, .01, [6, 6], "There's an awful smell here.", "Something green is moving toward you...")) {} else {
                MonsterZone([5, 13, 21], .05, -1, "", "Something lurches out of the darkness...");
                MonsterZone(34, .004, -1, "", "Something crawls out of the darkness toward you...")
            }
            if (Main.innerHTML.indexOf('<p>') == -1) Add("You're exploring a deep cave.")
        }
    }
    if (where == mHell) {
        if (Previous == subloc) {
            sound('m5');
            Add("You squeeze through the crevice into a fiery labyrinth. You hear screams in the distance.");
            MarkMap('E');
            Option("~Go back through the crevice", "CaveEx");
            MarkMap('E')
        } else {
            if (InZone([7, 0])) {
                Add("There's a crevice in the wall here, leading back into the cave system.");
                Option("~Go back through the crevice", "CaveEx");
                MarkMap('E')
            } else if (MonsterZone(24, .20, [13, 8], "You notice a foul smell. There's a layer of stagnant water on the ground here.", "The smell gets worse...")) {} else if (MonsterZone(23, .20, [4, 4], "You step into a steamy haze. There's an old boiler here.", "Something sharp scrapes against the wall...")) {} else if (MonsterZone(28, .20, [9, 10], "You enter a small, dark room. Various chains and hooks hang from the ceiling.", "The chains begin to sway out of control...")) {} else if (MonsterZone(40, .20, [7, 8], "This must be the very center of the diabolical labyrinth.")) {} else {
                if (TextZone("3,1,5,1 = You're in some sort of cell. There are scratches on the walls.")) {} else if (TextZone("9,1,11,1 = You're in some sort of cell. There are blood splatters on the walls.")) {} else if (TextZone("1,2,13,2 = You're traveling along the northern wall of the outer layer of the labyrinth.")) {} else if (TextZone("1,3,1,13 = You're traveling along the western wall of the outer layer of the labyrinth.")) {} else if (TextZone("13,3,13,13 = You're traveling along the eastern wall of the outer layer of the labyrinth.")) {} else if (TextZone("1,14,13,14 = You're traveling along the southern wall of the outer layer of the labyrinth.")) {} else if (TextZone("3,4,11,4 = You're traveling along the northern wall of a median layer of the labyrinth. It's quite hot here.")) {} else if (TextZone("3,5,3,11 = You're traveling along the western wall of a median layer of the labyrinth. It's quite hot here.")) {} else if (TextZone("11,5,11,11 = You're traveling along the eastern wall of a median layer of the labyrinth. It's quite hot here.")) {} else if (TextZone("3,12,11,12 = You're traveling along the southern wall of a median layer of the labyrinth. It's quite hot here.")) {} else if (TextZone("5,6,9,6 = You're traveling along the northern wall of the innermost layer of the labyrinth. It's extremely hot here.")) {} else if (TextZone("5,7,5,9 = You're traveling along the western wall of the innermost layer of the labyrinth. It's extremely hot here.")) {} else if (TextZone("9,7,9,9 = You're traveling along the eastern wall of the innermost layer of the labyrinth. It's extremely hot here.")) {} else if (TextZone("5,10,7,10 = You're traveling along the southern wall of the innermost layer of the labyrinth. It's extremely hot here.")) {}
                MonsterZone([36, 6], .05, [1, 1, 13, 14], "", "You hear a bloodcurdling sound...")
            }
        }
    }
    Option("<Return to your truck", mainloc);
    Tip("You can use your computer's arrow keys to explore. Map squares will become visible as you branch out.<br>Monsters appear randomly as you move. Certain monsters lurk in certain areas of the map, some more rarely than others. If you find a spot that sounds interesting, you can mark it.<br>Some maps contain doorways or portals to other locations that can only be accessed from that spot.")
}
Act("Intro");
typei = -1;
typetext = '';
talking = !1;

function Typewrite(i = -1, text) {
    typei = i;
    typetext = text;
    clearTimeout(typerT);
    if (typeof spoken == 'undefined') return;
    if (typeof tospeak == 'undefined') return;
    if (typei < typetext.length) {
        talking = !0;
        speed = 45;
        if (typei == -1) {
            speed = 400;
            tospeak.innerHTML = typetext
        } else {
            spoken.innerHTML = typetext.substring(0, i + 1);
            tospeak.innerHTML = typetext.substring(i + 1)
        }
        typei++;
        if (typetext.charAt(typei - 1) == " ") speed = 70;
        if (typetext.charAt(typei - 1) == ",") speed = 100;
        if (['.', '!', '?'].includes(typetext.charAt(typei - 1)) && typetext.charAt(typei) == ' ') speed = 300;
        typerT = setTimeout(function () {
            typerT = Typewrite(typei, typetext)
        }, speed)
    } else talking = !1
}

function cycledialog(monst) {
    lines = Dialog[monst].split('_');
    firstline = lines[0];
    if (lines.length > 1) {
        lines.shift();
        lines.push(firstline);
        Dialog[monst] = lines.join('_')
    }
    return firstline
}

function MonsterTalk(who) {
    monst = YourMonsters.indexOf(who);
    if (Parents[monst]) {
        par = Parents[monst].split(',');
        if (par.includes("40")) {
            par.splice(par.indexOf("40"), 1);
            line = cycledialog(par[0]);
            return line.split("").reverse().join("").toUpperCase()
        }
        nah = ["i", "you", "and", "the", "my", "me", "your", "i'll", "i'm", "you're", "you'll", "of", "with", "a", "an", "on", "in", "at", "to", "for", "than", "into"];
        xWords = Dialog[par[0]].split(/[\s,_\-!?.\[\]]+/).filter(Boolean).filter(function (e) {
            return !nah.includes(e.toLowerCase())
        });
        yWords = Dialog[par[1]].split(/[\s,_\-!?.\[\]]+/).filter(Boolean).filter(function (e) {
            return !nah.includes(e.toLowerCase())
        });
        Sentence = '';
        words = Math.floor(Math.random() * 5) + 3;
        for (i = 0; i < words; i++) {
            if (i > 0) Sentence += Pick([' ', ' ', ' ', ', ', '. ', '? ', '! ']);
            zWords = [];
            if (i % 2 === 0) zWords = xWords;
            else zWords = yWords;
            r = Math.floor(Math.random() * zWords.length);
            Sentence += zWords[r];
            if (Chance(.25) && r < zWords.length - 1) Sentence += ' ' + zWords[r + 1];
            if (Chance(.25) && r < zWords.length - 2) Sentence += ' ' + zWords[r + 2]
        }
        return Sentence.toUpperCase() + "!"
    }
    line = cycledialog(Monsters.indexOf(who));
    return line
}

function InZone(x1, y1 = -1, x2 = -1, y2 = -1) {
    if (x1.constructor === Array) {
        y2 = parseInt(x1[3]);
        x2 = parseInt(x1[2]);
        y1 = parseInt(x1[1]);
        x1 = parseInt(x1[0])
    }
    if (!x2 || x2 < 0) x2 = x1;
    if (!y2 || y2 < 0) y2 = y1;
    if (X >= x1 && X <= x2 && Y >= y1 && Y <= y2) return !0;
    else return !1
}

function TextZone(xymessage) {
    xy = xymessage.split('=')[0].split(',');
    message = xymessage.split('=')[1];
    if (InZone(xy)) {
        Add(message);
        return !0
    } else return !1
}

function zone(msg, x1, y1, x2, y2) {
    if (InZone(x1, y1, x2, y2)) Add(msg)
}

function MonsterZone(monst, odds, xy = -1, mainmessage = !1, encountermessage = !1, blinkingmessage = !1) {
    if (xy != -1 && !InZone(xy)) return !1;
    if (document.getElementById("encounter")) {
        return !1
    }
    if (mainmessage) Add(mainmessage);
    if (Previous.indexOf("Ex") == -1) return !0;
    if (monst.constructor === Array) monst = Pick(monst);
    if (Chance((1.1) - (.50 * Phero)) && (YourMonsters.includes(Monsters[monst]) || TruckMonsters.includes(monst))) {
        return !0
    }
    if (Chance(Math.min(odds + (.20 * Phero), .95))) {
        nomove = !0;
        setTimeout(function () {
            nomove = !1
        }, 500);
        if (encountermessage) Add(encountermessage);
        if (blinkingmessage) {
            Add("<span id='encounter'>" + blinkingmessage + "</span>")
        } else {
            content = "<span id='encounter'>" + Pick(['Uh oh', 'Yikes', 'Wow', 'Whoa', 'Holy moly', 'Crikey', 'Look out', 'Holy smokes', 'Gosh', 'Jeepers', 'Golly', 'Oh dear', 'Eep', 'Willikers', 'Great Scott', 'Mamma mia', 'Yowza', 'Heyo', 'Eek', 'Yipes', 'Ahh', 'Egad']) + "! ";
            if (monst == 37) content += "An Invisible Man appears! (Sort of.)";
            else {
                content += Pick([Article(Monsters[monst], !0).slice(0, 1).toUpperCase() + Article(Monsters[monst], !0).slice(1) + " appears!", "It's " + Article(Monsters[monst], !0) + "!"])
            }
            content += "</span>";
            Add(content)
        }
        Blink('encounter', 3);
        sound(Pick(['scare1', 'scare2', 'scare3', 'scare4']));
        Option("~Capture " + Article(Monsters[monst], !1, 'the'), "Capture_" + monst);
        return !0
    } else return !0
}

function Pos(map, xpos, ypos) {
    if (ypos < 0) return '0';
    else if (xpos < 0) return '0';
    else if (ypos >= map.length || xpos >= map[ypos].length) return '0';
    else return map[ypos].charAt(xpos)
}

function MarkMap(letter = '') {
    if (letter == '') {
        if (Pos(currentmap, X, Y) < 10) letter = 'M';
        else if (Pos(currentmap, X, Y) == 'M') letter = '4';
        else return
    }
    currentmap[Y] = currentmap[Y].substring(0, X) + letter + currentmap[Y].substring(X + 1);
    mapbox.innerHTML = ShowMap(currentmap)
}

function ShowDriveMap(loc) {
    fadeloop(1);
    lN = '';
    lS = '';
    lE = '';
    lW = '';
    lC = '';
    if (loc == 'Travel') {
        lC = 'Ranch';
        lN = 'Woods';
        lE = 'City';
        lS = 'Desert'
    }
    if (loc == 'Woods') {
        lC = 'Woods';
        lW = 'Castle';
        lS = 'Travel'
    }
    if (loc == 'Castle') {
        lC = 'Castle';
        lE = 'Woods'
    }
    if (loc == 'City') {
        lC = 'City';
        lN = 'Suburbs';
        lW = 'Travel'
    }
    if (loc == 'Suburbs') {
        lC = 'Suburbs';
        lS = 'City'
    }
    if (loc == 'Desert') {
        lC = 'Desert';
        lN = 'Travel';
        lW = 'Lake'
    }
    if (loc == 'Lake') {
        lC = 'Lake';
        lE = 'Desert'
    }
    if (lN) lN = '<a onclick=\'Act("' + lN + '"); return false;\' href=\'#\'>' + lN.replace('Travel', 'Ranch').toUpperCase() + '</a>';
    if (lS) lS = '<a onclick=\'Act("' + lS + '"); return false;\' href=\'#\'>' + lS.replace('Travel', 'Ranch').toUpperCase() + '</a>';
    if (lE) lE = '<a onclick=\'Act("' + lE + '"); return false;\' href=\'#\'>' + lE.replace('Travel', 'Ranch').toUpperCase() + '</a>';
    if (lW) lW = '<a onclick=\'Act("' + lW + '"); return false;\' href=\'#\'>' + lW.replace('Travel', 'Ranch').toUpperCase() + '</a>';
    if (lC != 'Ranch') lC = '<a class=\'bluelink\' onclick=\'Act("' + lC + 'Ex"); return false;\' href=\'#\'>' + lC.toUpperCase() + '</a>';
    else lC = '<a class=\'bluelink\' onclick=\'Act("Ranch"); return false;\' href=\'#\'>RANCH</a>';
    dmap = "<center><div id='nav' style='height:auto; display:inline-block;'>";
    dmap += "<table style='width:auto; margin: 1px'>";
    dmap += "<tr>  <td></td>  <td></td>";
    dmap += "<td>" + lN + "</td>";
    dmap += "<td></td>  <td></td> </tr>";
    dmap += "<tr> <td colspan='2'></td> <td>";
    if (lN) dmap += "<div class='vline'></div>";
    dmap += "</td> <td colspan='2'> </td> </tr>";
    dmap += "<tr>  <td>" + lW + "</td>  <td>";
    if (lW) dmap += "<div class='hline'></div>";
    dmap += "</td> <td><big>" + lC + "</big></td> <td>";
    if (lE) dmap += "<div class='hline'></div>";
    dmap += "</td>  <td>" + lE + "</td> </tr>";
    dmap += "<tr> <td colspan='2'></td> <td>";
    if (lS) dmap += "<div class='vline'></div>";
    dmap += "</td> <td colspan='2'> </td> </tr>";
    dmap += "<tr>  <td></td>  <td></td>";
    dmap += "<td>" + lS + "</td>";
    dmap += "<td></td>  <td></td> </tr>";
    dmap += "</table></div></center>";
    Main.innerHTML += dmap
}
currentmap = [];

function ShowNav(map) {
    content = '';
    currentmap = map;
    content += "<center><div id='nav'><div id='mapbox'>"
    content += ShowMap(map);
    content += "</div><div id='navbox'>"
    if (Pos(map, X, Y - 1) > '1') content += "<div onclick=\"GoN(); return false; \" class=\"Direction\"><div class='optnum'></div> &#8679;</div><br>";
    else content += "<div class=\"DirectionBlocked\">&nbsp;</div><br>";
    if (Pos(map, X - 1, Y) > '1') content += "<div onclick=\"GoW(); return false; \" class=\"Direction\"><div class='optnum'></div>&#8678;</div>";
    else content += "<div class=\"DirectionBlocked\">&nbsp;</div>";
    if (Pos(map, X + 1, Y) > '1') content += "<div onclick=\"GoE(); return false; \" class=\"Direction\"><div class='optnum'></div>&#8680;</div>";
    else content += "<div class=\"DirectionBlocked\">&nbsp;</div>";
    if (Pos(map, X, Y + 1) > '1') content += "<br><div onclick=\"GoS(); return false;  \" class=\"Direction\"><div class='optnum'></div>&#8681;</div>";
    else content += "<br><div class=\"DirectionBlocked\">&nbsp;</div>";
    content += "</div><div onclick='MarkMap(); return false;' class='Direction markbutton'>MARK MAP</div>"
    Main.innerHTML += content + "</div></center>"
}

function ShowMap(map) {
    content = '';
    for (var yy = 0; yy < map.length; yy++) {
        if (yy > 0) content += "<br>";
        for (var xx = 0; xx < map[yy].length; xx++) {
            if ((xx == X - 1 && yy == Y) || (xx == X + 1 && yy == Y) || (xx == X && yy == Y - 1) || (xx == X && yy == Y + 1)) {
                if (Pos(map, xx, yy) == '0') {
                    map[yy] = map[yy].substring(0, xx) + '1' + map[yy].substring(xx + 1)
                } else if (Pos(map, xx, yy) == '2') {
                    map[yy] = map[yy].substring(0, xx) + '3' + map[yy].substring(xx + 1)
                }
            } else if (xx == X && yy == Y && Pos(map, xx, yy) < '4') map[yy] = map[yy].substring(0, xx) + '4' + map[yy].substring(xx + 1);
            if (Pos(map, xx, yy) == '1') content += "<div id='maptile' class='mapwall' title='" + xx + " x " + yy + "'></div>";
            else if (Pos(map, xx, yy) >= '4') {
                mapclass = 'mappath';
                if (X == xx && Y == yy) mapclass += " mapyou";
                if (Pos(map, xx, yy) > '9') mapclass += " map" + Pos(map, xx, yy);
                content += "<div id='maptile' class='" + mapclass + "' title='" + xx + " x " + yy + "'></div>"
            } else if (Pos(map, xx, yy) == '3') {
                content += "<div id='maptile' class='mapperiph' title='" + xx + " x " + yy + "'></div>"
            } else content += "<div id='maptile' class='mapblank'></div>"
        }
    }
    return content
}
smove = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 2];

function GoN() {
    if (!nomove) {
        Y--;
        Act(Previous);
        sound('move' + smove[0]);
        smove.push(smove.shift())
    }
}

function GoS() {
    if (!nomove) {
        Y++;
        Act(Previous);
        sound('move' + smove[0]);
        smove.push(smove.shift())
    }
}

function GoW() {
    if (!nomove) {
        X--;
        Act(Previous);
        sound('move' + smove[0]);
        smove.push(smove.shift())
    }
}

function GoE() {
    if (!nomove) {
        X++;
        Act(Previous);
        sound('move' + smove[0]);
        smove.push(smove.shift())
    }
}

function Say(text) {
    Main.innerHTML = "<p>" + text + "</p>"
}

function Add(text) {
    Main.innerHTML += "<p>" + text + "</p>"
}

function Article(text, caps = !1, custom = !1) {
    result = text;
    if (caps) result = text.toUpperCase();
    if (GetTrait(text, 'pn')) return result;
    else if (custom && custom != "A") return custom + " " + result;
    else if (['a', 'e', 'i', 'o', 'u'].includes(text.toLowerCase().charAt(0))) {
        if (custom == "A") return "An " + result;
        else return "an " + result
    } else {
        if (custom == "A") return "A " + result;
        else return "a " + result
    }
}

function GetTrait(monstername, trait) {
    monst = Monsters.indexOf(monstername);
    if (monst == -1) return !1;
    if (Traits[monst].indexOf(trait + "=") > -1) {
        bleh = Traits[monst].substring(Traits[monst].indexOf(trait + "=")).split("=")[1].split("\t")[0];
        return bleh
    } else if (Traits[monst].indexOf(trait) > -1) return !0;
    else return !1
}

function GetTraits(monstername) {
    monst = Monsters.indexOf(monstername);
    tl = Traits[monst].split(' ').filter(function (e) {
        return (e != 'pn' && e != 'rr')
    });
    return tl
}

function aHybridizeTraits(traits1, traits2) {
    tl = traits1.concat(traits2);
    if (tl.indexOf('sm') != -1 && tl.indexOf('md') != -1) tl = tl.filter(e => e !== 'sm');
    if (tl.indexOf('md') != -1 && tl.indexOf('lg') != -1) tl = tl.filter(e => e !== 'md');
    if (tl.indexOf('lg') != -1 && tl.indexOf('hg') != -1) tl = tl.filter(e => e !== 'lg');
    if (tl.indexOf('md') != -1 && tl.indexOf('hg') != -1) tl = tl.filter(e => e !== 'md');
    if (tl.indexOf('sm') != -1 && tl.indexOf('hg') != -1) tl = tl.filter(e => e !== 'sm');
    if (tl.indexOf('sm') != -1 && tl.indexOf('lg') != -1) tl = tl.filter(e => e !== 'sm');
    if (tl.indexOf('qt') != -1 && tl.indexOf('ld') != -1) tl = tl.filter(e => e !== 'qt');
    if (tl.indexOf('hy') != -1 && tl.indexOf('hl') != -1) tl = tl.filter(e => e !== 'hy');
    if (tl.indexOf('sl') != -1 && tl.indexOf('fs') != -1) tl = tl.filter(e => e !== 'sl');
    if (tl.indexOf('ml') != -1 && tl.indexOf('ll') != -1) tl = tl.filter(e => e !== 'll');
    unduped = tl.filter(function (item, pos) {
        return tl.indexOf(item) == pos
    }).filter(function (n) {
        return n != undefined
    });
    return unduped
}

function HybridizeTraits(bodym, headm) {
    body = GetTraits(bodym);
    head = GetTraits(headm);
    if (bodym == 'Headless Horseman') {
        body = GetTraits(headm);
        head = []
    }
    if (headm == 'Headless Horseman') {
        body = GetTraits(bodym);
        head = []
    }
    if (bodym == 'Invisible Man') {
        head = GetTraits(headm);
        body = GetTraits(headm);
        body.push('tr')
    }
    if (headm == 'Invisible Man') {
        head = GetTraits(bodym);
        body = GetTraits(bodym);
        body.push('tr')
    }
    either = body.concat(head);
    inherit = [];
    if (body.includes('hg')) inherit.push('hg');
    else if (body.includes('lg')) inherit.push('lg');
    else if (body.includes('md')) inherit.push('md');
    else if (body.includes('sm')) inherit.push('sm');
    if (either.includes('aq')) inherit.push('aq');
    if (body.includes('fl')) inherit.push('fl');
    if (head.includes('qt')) inherit.push('qt');
    else if (head.includes('ld')) inherit.push('ld');
    if (body.includes('wp')) inherit.push('wp');
    if (head.includes('bt')) inherit.push('bt');
    if (either.includes('fr')) inherit.push('bt');
    if (either.includes('dd')) inherit.push('dd');
    if (either.includes('al')) inherit.push('al');
    if (either.includes('dm')) inherit.push('dm');
    if (either.includes('hy')) inherit.push('hy');
    else if (either.includes('hl')) inherit.push('hl');
    if (either.includes('is')) inherit.push('is');
    if (either.includes('cy')) inherit.push('cy');
    if (head.includes('cb')) inherit.push('cb');
    if (body.includes('ml')) inherit.push('ml');
    if (body.includes('ll')) inherit.push('ll');
    if (either.includes('gc')) inherit.push('gc');
    if (either.includes('io')) inherit.push('io');
    if (head.includes('mc')) inherit.push('mc');
    if (either.includes('fu')) inherit.push('fu');
    else if (either.includes('ol')) inherit.push('ol');
    if (body.includes('fs')) inherit.push('fs');
    else if (body.includes('sl')) inherit.push('sl');
    if (either.includes('tr')) inherit.push('tr');
    if (either.includes('sy')) inherit.push('sy');
    if (either.includes('ss')) inherit.push('ss');
    if (head.includes('it')) inherit.push('it');
    if (either.includes('hu')) inherit.push('hu');
    if (head.includes('sd')) inherit.push('sd');
    if (either.includes('nc')) inherit.push('nc');
    if (either.includes('mg')) inherit.push('mg');
    if (body.includes('ct')) inherit.push('ct');
    if (body.includes('sh')) inherit.push('sh');
    if (either.includes('my')) inherit.push('my');
    if (head.includes('st')) inherit.push('st');
    if (either.includes('an')) inherit.push('an');
    if (either.includes('sf')) inherit.push('sf');
    if (either.includes('gr')) inherit.push('gr');
    return inherit
}

function testtraits() {
    i = 0;
    while (i < MonsterPair.length) {
        t = HybridizeTraits(MonsterPair[i].split(',')[0], MonsterPair[i].split(',')[1]);
        if (t.filter(e => traits.indexOf(e) > -1).length == traits.length) console.log(Hybrid[i]);
        i++
    }
}
prizemoney = 0;

function Pageant() {
    m1 = '';
    m2 = '';
    trar = -1;
    if (Pag.length < 3) {
        if (isNaN(Pag[0]) == !1 && isNaN(Pag[1]) == !1) {
            m1 = Monsters[Pag[0]];
            m2 = Monsters[Pag[1]];
            Pag = [];
            prizemoney = 0
        }
    } else {
        traits = Pag.slice()
    }
    jam = 0;
    while (Pag.length == 0 && jam < 10) {
        if (jam > 2) {
            m1 = '';
            m2 = '';
            jam = 0
        }
        while (m1 == m2) {
            mlen = Monsters.length;
            m1 = Monsters[Math.floor(Math.random() * mlen)];
            m2 = Monsters[Math.floor(Math.random() * mlen)]
        }
        Pag = [];
        traits = HybridizeTraits(m1, m2);
        sz = traits.filter(e => ['sm', 'md', 'lg', 'hg'].includes(e));
        traits = traits.filter(e => !['sm', 'md', 'lg', 'hg'].includes(e));
        if (traits.length > 7) {
            traits.sort(function () {
                return .5 - Math.random()
            });
            traits.splice(7)
        }
        traits.unshift(sz[0]);
        Pag = traits.slice();
        m1t = GetTraits(m1);
        m2t = GetTraits(m2);
        trar = traitrarity();
        if (trar > 6) {
            Pag = [];
            jam++
        }
    }
    desc = [];
    if (traits.includes('sm')) size = 'Small';
    if (traits.includes('md')) size = 'Medium';
    if (traits.includes('lg')) size = 'Large';
    if (traits.includes('hg')) size = 'Gigantic';
    if (traits.includes('aq')) desc.push('swimming ability');
    if (traits.includes('fl')) desc.push('flying ability');
    if (traits.includes('qt')) desc.push('quietness');
    if (traits.includes('ld')) desc.push('loudness');
    if (traits.includes('wp')) desc.push('weapon skills');
    if (traits.includes('bt')) desc.push('biting ability');
    if (traits.includes('fr')) desc.push('flamethrowing ability');
    if (traits.includes('dd')) desc.push('undeadness');
    if (traits.includes('al')) desc.push('alien presence');
    if (traits.includes('dm')) desc.push('demonic presence');
    if (traits.includes('hy')) desc.push('hairiness');
    if (traits.includes('gr')) desc.push('green coloration');
    if (traits.includes('is')) desc.push('insectlike look');
    if (traits.includes('cy')) desc.push('cuddliness');
    if (traits.includes('cb')) desc.push('cannibalism');
    if (traits.includes('ml')) desc.push('leg count');
    if (traits.includes('ll')) desc.push('leglessness');
    if (traits.includes('gc')) desc.push('gothic style');
    if (traits.includes('io')) desc.push('manufacture');
    if (traits.includes('mc')) desc.push('mischief');
    if (traits.includes('ol')) desc.push('agedness');
    if (traits.includes('sl')) desc.push('slowness');
    if (traits.includes('fs')) desc.push('quickness');
    if (traits.includes('tr')) desc.push('translucence');
    if (traits.includes('sy')) desc.push('odor');
    if (traits.includes('fu')) desc.push('futuristic look');
    if (traits.includes('ss')) desc.push('shapeshifting ability');
    if (traits.includes('it')) desc.push('intelligence');
    if (traits.includes('hl')) desc.push('hairlessness');
    if (traits.includes('hu')) desc.push('human presence');
    if (traits.includes('sd')) desc.push('tragic personality');
    if (traits.includes('nc')) desc.push('nocturnality');
    if (traits.includes('mg')) desc.push('dark magic');
    if (traits.includes('ct')) desc.push('attire');
    if (traits.includes('sh')) desc.push('shapelessness');
    if (traits.includes('my')) desc.push('mythology');
    if (traits.includes('st')) desc.push('stupidity');
    if (traits.includes('an')) desc.push('animality');
    if (traits.includes('sf')) desc.push('sci-fi origins');
    descr = ''
    for (i = 0; i < desc.length - 1; i++) {
        descr += '• ' + desc[i].toUpperCase();
        descr += '<br>'
    }
    descr += '• and ' + desc[desc.length - 1].toUpperCase();
    if (trar < 1) {
        trar = traitrarity()
    }
    prizemoney = 5000 + (5000 * (6 - trar));
    prizetxt = prizemoney.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    Say('<center>&#9733;&#9733;&#9733; <i>Monster Beauty Pageant</i> &#9733;&#9733;&#9733;<br><br><big>$' + prizetxt + ' GRAND PRIZE</big><br><br>' + size.toUpperCase() + ' Weight Class<br><br></center>');
    Add('We are now accepting entries! Show monsters will be judged based on:<br>' + descr + '');
    Add('<br><small><small>One monster per breeder allowed per contest. New contests held regularly. Entry fees will not be refunded.</small></small><br><br>');
    Add("Entry fee: $1,000<br>You have: $" + Cash.toLocaleString());
    Option();
    if (Cash >= 1000) Option("Enter a Monster", "SubmitPageant");
    Option("<Back", "Catalog");
    Tip("Pageant judges are looking for a monster you probably don't have yet. To win, you'll have to go out and find the right monsters, and breed them in the right order (although in theory, some contests could be won by a non-hybrid monster.)<br>The same contest will run until you enter a monster. After you've won or lost, a new contest will begin with new criteria.");
    m1 = '';
    m2 = ''
}

function traitrarity() {
    i = 0;
    tct = 0;
    while (i < MonsterPair.length) {
        t = HybridizeTraits(MonsterPair[i].split(',')[0], MonsterPair[i].split(',')[1]);
        if (t.filter(e => traits.indexOf(e) > -1).length == traits.length) {
            tct++
        }
        t = HybridizeTraits(MonsterPair[i].split(',')[1], MonsterPair[i].split(',')[0]);
        if (t.filter(e => traits.indexOf(e) > -1).length == traits.length) {
            tct++
        }
        i++
    }
    return tct
}

function sortmonsters() {
    MoS = [];
    HyS = [];
    for (i = 0; i < YourMonsters.length; i++) {
        if (Parents[i]) HyS.push([YourMonsters[i], i]);
        else MoS.push([YourMonsters[i], i])
    }
    MoS = MoS.sort();
    HyS = HyS.sort();
    newMon = [];
    newPar = [];
    newFlag = [];
    for (i = 0; i < MoS.length; i++) {
        newMon.push(MoS[i][0]);
        newPar.push(Parents[MoS[i][1]]);
        newFlag.push(Flags[MoS[i][1]])
    }
    for (i = 0; i < HyS.length; i++) {
        newMon.push(HyS[i][0]);
        newPar.push(Parents[HyS[i][1]]);
        newFlag.push(Flags[HyS[i][1]])
    }
    YourMonsters = newMon;
    Parents = newPar;
    Flags = newFlag;
    Act('List Monsters')
}

function optsort() {
    if (document.querySelectorAll(".Opt").length > 12) {
        document.querySelectorAll("#Under")[0].classList.add("column")
    } else {
        document.querySelectorAll("#Under")[0].classList.remove("column")
    }
}
optsort();
optcount = 0;

function Option() {
    if (arguments.length == 0) {
        Under.innerHTML = "";
        UnderUnder.innerHTML = "";
        optcount = 0
    } else {
        optcount++;
        if (optcount > 36) opttag = '';
        else {
            if (optcount == 10) optn = 0;
            else if (optcount > 10) optn = String.fromCharCode(optcount + 54);
            else optn = optcount;
            opttag = '<div class="optnum">' + optn + '</div>'
        }
        if (optcount == 0) optcount = 100;
        if (arguments[0] == "<Return to your truck" && Gear.indexOf("ph") > -1 && !Phero) {
            Under.innerHTML += "<div onclick=\"Act(\'UsePhero\'); return false;\" class=\"Opt\" id=\"useph\">" + opttag + "Use Pheromones</div>"
        }
        if (arguments[0].indexOf("<") == 0) {
            arguments[0] = arguments[0].replace("<", "&#8592;");
            UnderUnder.innerHTML += "<div onclick=\"Act(\'" + arguments[1] + "\'); return false;\" class=\"Opt BackOpt\">" + '<div class="optnum">esc</div>' + arguments[0] + "</div>"
        } else if (arguments[0].indexOf("=") == 0) {
            arguments[0] = arguments[0].replace("=", "");
            Under.innerHTML += "<div onclick=\"" + arguments[1] + " return false;\" class=\"Opt BackOpt\">" + opttag + arguments[0] + "</div>"
        } else if (arguments[0].indexOf("~") == 0) {
            arguments[0] = arguments[0].replace("~", "");
            Under.innerHTML += "<div onclick=\"Act(\'" + arguments[1] + "\'); return false;\" class=\"Opt XOpt\">" + opttag + arguments[0] + "</div>"
        } else {
            if (arguments[1] == "") arguments[1] = arguments[0];
            Under.innerHTML += "<div onclick=\"Act(\'" + arguments[1] + "\'); return false;\" id=\"" + arguments[0] + "\" class=\"Opt\">" + opttag + arguments[0] + "</div>"
        }
    }
    optsort()
}

function ToggleStats(onoff = 0) {
    if (onoff == 2 && Stats.innerHTML == "") {
        content = "<p style='text-indent:30px;'>[LOG]</p>";
        content += "<div id='logbox' style='max-height:200px; height:auto; min-width:100%; overflow:auto;'>";
        content += Log;
        content += "</div>";
        MenuBar.innerHTML = "<small>    <a href='#' onclick='ToggleStats(0); return false;'>CLOSE &#9650;</a>   </small>"
        Stats.innerHTML = content;
        logbox.scrollTop = logbox.scrollHeight
    } else if (onoff == 1 && Stats.innerHTML == "") {
        content = "<p style='text-indent:30px;'>[STATS]</p>";
        content += "<p>MONEY: $" + Cash + "</p>";
        content += "<p>TRUCK CAPACITY: " + TruckCap + " units (" + Math.floor((Weight(TruckMonsters) / TruckCap) * 100) + "% full)</p>";
        if (Gear.length > 0) {
            gearlist = [];
            content += "<p>GEAR: ";
            if (Gear.indexOf("aq") > -1) gearlist.push("Aquatic Gear");
            if (Gear.indexOf("fl") > -1) gearlist.push("Aerial Gear");
            if (Gear.indexOf("ph") > -1) {
                phcount = 0;
                for (var i = 0; i < Gear.length; ++i) {
                    if (Gear[i] == "ph") phcount++
                }
                gearlist.push("Pheromones (" + phcount + " units)")
            }
            if (Gear.indexOf("lc") > -1) gearlist.push("Breeding License");
            content += gearlist.join(", ")
        }
        if (YourMonsters[0] != '0' || TruckMonsters.length > 0) content += "<p style='text-indent:30px;'>[MONSTERS]</p>";
        if (TruckMonsters.length > 0) {
            Trucknames = [];
            for (i = 0; i < TruckMonsters.length; i++) {
                if (TruckMonsters[i] > -1) Trucknames.push(Monsters[TruckMonsters[i]])
            }
            content += "<p>IN TRUCK: " + Trucknames.join(', ') + "</p>"
        }
        if (YourMonsters[0] != '0') {
            content += "<p>IN STABLES: " + YourMonsters.join(', ') + "</p>";
            content += "<p>" + HybridsBred();
            if (HybridsBred() == 1) content += " crossbreed discovered.";
            else {
                content += " crossbreeds discovered."
            }
            content += " (" + (Math.round((HybridsBred() / Hybrid.length) * 1000) / 10) + "%)</p>"
        }
        MenuBar.innerHTML = "<small>    <a href='#' onclick='ToggleStats(0); return false;'>CLOSE &#9650;</a>   </small>"
        Stats.innerHTML = content
    } else {
        MenuBar.innerHTML = "<small>    <a href='#' onclick='ToggleStats(2); return false;'>LOG &#9660;</a>&emsp;<a href='#' onclick='ToggleStats(1); return false;'>STATS &#9660;</a> </small>";
        Stats.innerHTML = ""
    }
}

function LogLine(text) {
    if (Log != '') Log += "<br>"
    Log += text
}

function HybridsBred() {
    return Bred.join("").length
}

function HybridsInStable(unsold = !1) {
    ct = 0;
    for (i = 0; i < Parents.length; i++) {
        if (Parents[i]) {
            if (!unsold || !recentsales.includes(YourMonsters[i])) ct++
        }
    }
    return ct
}

function ComboCheck(mon1, mon2) {
    var found = -1;
    order1 = mon1.toUpperCase().trim() + "," + mon2.toUpperCase().trim();
    order2 = mon2.toUpperCase().trim() + "," + mon1.toUpperCase().trim();
    for (var i = 0; i < MonsterPair.length; i++) {
        if (MonsterPair[i].toUpperCase().trim() == order1 || MonsterPair[i].toUpperCase().trim() == order2) {
            found = i;
            break
        }
    }
    return found
}

function MonsterList(prefix) {
    for (var i = 0; i < YourMonsters.length; i++) {
        if (Parents[i]) {
            Option("~• " + YourMonsters[i], prefix + i)
        } else Option("• " + YourMonsters[i], prefix + i)
    }
}

function CrossbreedList(prefix) {
    for (var i = 0; i < YourMonsters.length; i++) {
        if (Parents[i]) {
            Option("~• " + YourMonsters[i], prefix + i)
        }
    }
}

function Sleep(delay) {
    var startTime = new Date();
    var endTime = null;
    do {
        endTime = new Date()
    } while ((endTime - startTime));
}

function Blink(target, times) {
    length = 200;
    if (!document.getElementById(target)) return;
    for (var i = 0; i < times; i++) {
        blinkerT[i * 2] = setTimeout(function () {
            document.getElementById(target).style.visibility = "hidden"
        }, length + (i * length * 2));
        blinkerT[(i * 2) + 1] = setTimeout(function () {
            document.getElementById(target).style.visibility = ""
        }, length * 2 + (i * length * 2))
    }
}

function killTimeouts() {
    clearTimeout(typerT);
    if (document.getElementById("tospeak")) document.getElementById("tospeak").remove();
    if (document.getElementById("spoken")) document.getElementById("spoken").remove();
    for (var i in blinkerT) {
        clearTimeout(blinkerT[i])
    }
}

function Chance(perc) {
    if (Math.random() < perc) return !0;
    else return !1
}

function Pick(arguments) {
    return arguments[Math.floor(Math.random() * arguments.length)]
}

function LoseMonster(monst) {
    YourMonsters.splice(monst, 1);
    Parents.splice(monst, 1);
    Flags.splice(monst, 1)
}

function Weight(input) {
    wght = 0;
    lst = [];
    if (Array.isArray(input)) {
        lst = input
    } else lst.push(input);
    for (var i = 0; i < lst.length; i++) {
        if (GetTrait(Monsters[lst[i]], 'sm')) wght += 1;
        else if (GetTrait(Monsters[lst[i]], 'md')) wght += 3;
        else if (GetTrait(Monsters[lst[i]], 'lg')) wght += 10;
        else if (GetTrait(Monsters[lst[i]], 'hg')) wght += 20
    }
    return wght
}
click = -1;
clicking = !1;
document.onkeydown = function (e) {
    if (clicking) {
        return
    }
    click = -1;
    if (document.getElementById("navbox") != null) {
        switch (e.keyCode) {
            case 38:
                e.preventDefault();
                if (Pos(currentmap, X, Y - 1) > '1') {
                    click = document.getElementById('navbox').children[0];
                    click.className += ' hov';
                    doclick()
                }
                break;
            case 37:
                e.preventDefault();
                if (Pos(currentmap, X - 1, Y) > '1') {
                    click = document.getElementById('navbox').children[2];
                    click.className += ' hov';
                    doclick()
                }
                break;
            case 39:
                e.preventDefault();
                if (Pos(currentmap, X + 1, Y) > '1') {
                    click = document.getElementById('navbox').children[3];
                    click.className += ' hov';
                    doclick()
                }
                break;
            case 40:
                e.preventDefault();
                if (Pos(currentmap, X, Y + 1) > '1') {
                    click = document.getElementById('navbox').children[5];
                    click.className += ' hov';
                    doclick()
                }
                break;
            case 77:
                MarkMap()
        }
    }
    e = e || window.event;
    e = parseInt(e.keyCode)
    if (e == 220) breedchart();
    if ((e >= 48 && e <= 57) || (e >= 96 && e <= 105) || (e >= 65 && e <= 90) || e == 27) {
        if (e == 48) ek = 0;
        else if (e >= 65 && e <= 90) ek = String.fromCharCode(e);
        else if (e == 96) ek = 0;
        else if (e > 96) ek = e - 96;
        else ek = e - 48;
        optos = document.getElementById('Under');
        backo = document.getElementById('UnderUnder');
        if (e == 27 && backo.children[0] && backo.children[0].children[0].innerHTML == 'esc') click = backo.children[0];
        else {
            for (i = 0; i < optos.children.length; i++) {
                if (optos.children[i].children[0] && optos.children[i].children[0].innerHTML == ek) click = optos.children[i]
            }
        }
        if (typeof click === "object") click.className += ' hov';
        if (click != -1) doclick()
    }
    if (e == 192) {
        click = document.getElementById('Stats').onclick()
    }
    clicking = !0
}
document.onkeyup = function (e) {
    clicking = !1
}

function doclick() {
    setTimeout(function () {
        click.onclick();
        click = -1
    }, 50)
}

function sound(file) {
    if (music) {
        msound = new Audio('sound/' + file + '.ogg');
        msound.currentTime = 0;
        msound.play()
    }
}

function walkmusic(file) {
    if (!music) {
        mwalkfile = file
    } else if (mwalk.paused == !1 && file == mwalkfile) {} else {
        mwalk = new Audio('sound/' + file + '.ogg');
        mwalkfile = file;
        mwalk.currentTime = 0;
        mwalk.play();
        mwalk.addEventListener('timeupdate', function () {
            var buffer = .34;
            if (this.currentTime > this.duration - buffer) {
                this.currentTime = 0;
                this.play()
            }
        }, !1)
    }
}

function stopwalkmusic() {
    if (mloop[1]) {
        mloop[1].pause();
        loopfile[1] = '';
        clearTimeout(looptimer[1])
    }
}

function ToggleMusic() {
    if (music) {
        document.getElementById('togmus').style.textDecoration = 'line-through';
        clearTimeout(looptimer[0]);
        clearTimeout(looptimer[1]);
        clearTimeout(fadetimer[0]);
        clearTimeout(fadetimer[1]);
        if (mloop[0]) fadeloop(0, !0);
        if (mloop[1]) fadeloop(1, !0);
        music = !1
    } else {
        document.getElementById('togmus').style.textDecoration = 'none';
        music = !0;
        randomloop(mloops, 0);
        if (loopfile[1]) randomloop(mwalks, 1)
    }
}
colorscheme = 'n';

function ToggleColor() {
    if (colorscheme == 'n') {
        document.getElementById('togcol').innerHTML = 'Night Mode';
        document.documentElement.style.setProperty('--main-base-color', '#AACCDD');
        document.documentElement.style.setProperty('--gui-color', '#CCCCCC');
        document.documentElement.style.setProperty('--gui-highlight', '#6F91A2');
        document.documentElement.style.setProperty('--gui-shadow', '#6F91A2');
        document.documentElement.style.setProperty('--button-color', '#AACCAA');
        document.documentElement.style.setProperty('--button-highlight', '#55AA55');
        document.documentElement.style.setProperty('--button-shadow', '#55AA55');
        document.documentElement.style.setProperty('--link-color', '#11AA11');
        document.documentElement.style.setProperty('--link-hover', '#116611');
        document.documentElement.style.setProperty('--x-color', '#BBBBFF');
        document.documentElement.style.setProperty('--x-highlight', '#7777CC');
        document.documentElement.style.setProperty('--x-shadow', '#7777CC');
        document.documentElement.style.setProperty('--x-hover', '#222266');
        document.documentElement.style.setProperty('--text-color', '#335566');
        document.documentElement.style.setProperty('--map-wall', '#AACCDD');
        document.documentElement.style.setProperty('--map-spot', '#335566');
        document.documentElement.style.setProperty('--map-path', '#888888');
        document.documentElement.style.setProperty('--map-periph', '#99AAB3');
        document.documentElement.style.setProperty('--nav-color', '#AACCDD');
        document.documentElement.style.setProperty('--speech-color', '#5566EE');
        colorscheme = 'd'
    } else {
        document.getElementById('togcol').innerHTML = 'Day Mode';
        document.documentElement.style.setProperty('--main-base-color', '#000000');
        document.documentElement.style.setProperty('--gui-color', '#000000');
        document.documentElement.style.setProperty('--gui-highlight', '#AA00AA');
        document.documentElement.style.setProperty('--gui-shadow', '#550055');
        document.documentElement.style.setProperty('--button-color', '#000000');
        document.documentElement.style.setProperty('--button-highlight', '#00AA00');
        document.documentElement.style.setProperty('--button-shadow', '#005500');
        document.documentElement.style.setProperty('--link-color', '#00AA00');
        document.documentElement.style.setProperty('--link-hover', '#AAFFAA');
        document.documentElement.style.setProperty('--x-color', '#000000');
        document.documentElement.style.setProperty('--x-highlight', '#00AAAA');
        document.documentElement.style.setProperty('--x-shadow', '#005555');
        document.documentElement.style.setProperty('--x-hover', '#AAFFFF');
        document.documentElement.style.setProperty('--text-color', '#AA00AA');
        document.documentElement.style.setProperty('--map-wall', '#000000');
        document.documentElement.style.setProperty('--map-spot', '#000000');
        document.documentElement.style.setProperty('--map-path', '#00AAAA');
        document.documentElement.style.setProperty('--map-periph', '#005555');
        document.documentElement.style.setProperty('--nav-color', '#000000');
        document.documentElement.style.setProperty('--speech-color', '#AAAAAA');
        colorscheme = 'n'
    }
}

function cht() {
    document.getElementById('cht').style.display = 'inline-block'
}

function sendEvent(category, label, value = 0) {
    try {
        gtag('event', 'game', {
            'event_category': category,
            'event_label': label,
            'value': value
        })
    } catch (error) {}
}
chart = [];
monsP = [];
monsts = [];

function breedchart() {
    for (zi = 0; zi < MonsterPair.length; zi++) {
        mons = MonsterPair[zi].split(',');
        mA = Monsters.indexOf(mons[0]);
        mB = Monsters.indexOf(mons[1]);
        if (YourMonsters.includes(Monsters[mA])) monsts[mA] = 1;
        if (YourMonsters.includes(Monsters[mB])) monsts[mB] = 1;
        if (Bred[zi]) {
            monsts[mA] = 1;
            monsts[mB] = 1;
            monsP[zi] = [mA, mB].sort().join('-')
        }
    }
    chartdiv = document.getElementById('breedchart');
    tablehtml = '';
    for (zi = 0; zi < Monsters.length; zi++) {
        rowhtml = '';
        for (zii = 0; zii < Monsters.length; zii++) {
            classes = 'pairblock';
            if (monsts[zi] == 1 && monsts[zii] == 1) classes += ' unbred';
            else if (monsts[zi] == 1 || monsts[zii] == 1) classes += ' caught';
            combo = monsP.indexOf([zi, zii].sort().join('-'));
            classes += ' ' + zi + ' ' + zii;
            if (zi <= zii) {
                classes = 'pairblock nopair';
                mouseover = ''
            } else {
                mouseover = "onmouseover='breedid(\"";
                if (Bred[combo]) classes += ' bred'
            }
            zid = zi + ',' + zii;
            rowhtml += "<div ";
            if (zi != zii) rowhtml += mouseover + zid + "\");'";
            rowhtml += " class='" + classes + "' id='" + zid + "'></div>"
        }
        tablehtml += rowhtml + "<br>"
    }
    chartdiv.innerHTML = "<center>" + tablehtml + "<div id='breedinfo' style='height:120px'> </div></center>";
    chartdiv.style.display = 'block'
}

function breedid(zid) {
    iddiv = document.getElementById('breedinfo');
    chartdiv = document.getElementById('breedchart');
    ids = zid.split(',');
    if (ids.length > 1) {
        zmon1 = parseInt(ids[0]);
        zmon2 = parseInt(ids[1]);
        if (zmon1 == zmon2) iddiv.innerHTML = '';
        else {
            combo = monsP.indexOf([zmon1, zmon2].sort().join('-'));
            if (monsts[zmon1]) M1 = Monsters[zmon1];
            else M1 = "?";
            if (monsts[zmon2]) M2 = Monsters[zmon2];
            else M2 = "?";
            if (Bred[combo]) M3 = Hybrid[combo];
            else M3 = '?';
            iddiv.innerHTML = "<div style='width:650px; display: flex; flex-direction: row;'><div style='color:#800; width:200px;'>" + M1 + "</div>+<div style='color:#080; width:200px;'>" + M2 + "</div>=<div style='color:#DD0; width:200px;'>" + M3 + "</div></div>";
            var elements = chartdiv.querySelectorAll('.pairblock');
            for (var zi = 0; zi < elements.length; zi++) {
                elements[zi].classList.remove("pbA");
                elements[zi].classList.remove("pbB");
                if (elements[zi].classList.contains(zmon1)) elements[zi].classList.add("pbA");
                if (elements[zi].classList.contains(zmon2)) elements[zi].classList.add("pbB")
            }
        }
    }
}

function ShowMonster(mon = -1, wildmon = -1) {
    monid = [-1];
    if (mon == -1) {
        monid[0] = wildmon;
        monid[1] = wildmon
    } else if (Parents[mon]) {
        monid[0] = Parents[mon].split(',')[0];
        monid[1] = Parents[mon].split(',')[1];
        if (monid[0] == 22) monid.reverse();
        if (monid.indexOf('37') != -1) {
            monid[0] = 37;
            monid[1] = 37
        }
    } else {
        monid[0] = Monsters.indexOf(YourMonsters[mon]);
        if (monid[0] == 36 || monid[0] == 42 || monid[0] == 33) {
            monid[0] += 1000
        }
        monid[1] = monid[0]
    }
    if (monid[0] != -1) {
        imgb = "<img src='art/" + monid[1] + "h.gif' id='monsterhead'></img>";
        imgh = "<img src='art/" + monid[0] + "b.gif' id='monsterbod'></img>";
        monimg = "<div id='monsterimagecontainer'><div id='blackimage'><div id='imagespacer'></div><div id='monsterimage'>" + imgb + imgh + "</div></div></div></div>";
        return monimg
    } else return ''
}

function HideMonsterImage() {
    document.getElementById('monsterhead').style.visibility = 'hidden';
    document.getElementById('monsterbod').style.visibility = 'hidden';
    monsterimageCheck = setInterval(CheckMonsterImage, 100)
}

function CheckMonsterImage() {
    mh = document.getElementById('monsterhead');
    mb = document.getElementById('monsterbod');
    if (mh.complete && mb.complete) {
        mh.style.visibility = 'visible';
        mb.style.visibility = 'visible';
        clearInterval(monsterimageCheck)
    }
}

function Tip(text) {
    toadd = '<p id="tiptext"> <a href="#" onclick="ShowTip(&quot;' + text + '&quot;); return false;">tip</a></p>';
    toadd += '<div style="clear:both;"></div>';
    Main.innerHTML += toadd
}

function ShowTip(text) {
    toadd = "<p id='tip' onclick='tip.remove()'><span style='float:right'>X</span> " + text + "</p>";
    tiptext.innerHTML += toadd
}
-->
